mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-11-05 23:09:02 +00:00
CHANGED: #1471 Moved the stuff I moved to NELGUI library, under the NLGUI namespace.
This commit is contained in:
parent
731d1ced46
commit
c817c68e83
21 changed files with 2318 additions and 2274 deletions
|
@ -19,8 +19,9 @@
|
||||||
|
|
||||||
#include "nel/misc/types_nl.h"
|
#include "nel/misc/types_nl.h"
|
||||||
#include "nel/gui/lua_helper.h"
|
#include "nel/gui/lua_helper.h"
|
||||||
using namespace NLGUI;
|
|
||||||
|
|
||||||
|
#define IHM_LUA_METATABLE "__ui_metatable"
|
||||||
|
#define IHM_LUA_ENVTABLE "__ui_envtable"
|
||||||
|
|
||||||
namespace NLMISC
|
namespace NLMISC
|
||||||
{
|
{
|
||||||
|
@ -29,20 +30,23 @@ namespace NLMISC
|
||||||
class CRGBA;
|
class CRGBA;
|
||||||
}
|
}
|
||||||
|
|
||||||
class CReflectable;
|
namespace NLGUI
|
||||||
class CReflectedProperty;
|
{
|
||||||
|
|
||||||
// ***************************************************************************
|
class CReflectable;
|
||||||
/* Use this Exception for all LUA Error (eg: scripted passes bad number of paramters).
|
class CReflectedProperty;
|
||||||
|
|
||||||
|
// ***************************************************************************
|
||||||
|
/* Use this Exception for all LUA Error (eg: scripted passes bad number of paramters).
|
||||||
* Does not herit from Exception because avoid nlinfo, because sent twice (catch then resent)
|
* Does not herit from Exception because avoid nlinfo, because sent twice (catch then resent)
|
||||||
* This is special to lua and IHM since it works with CLuaStackChecker, and also append to the error msg
|
* This is special to lua and IHM since it works with CLuaStackChecker, and also append to the error msg
|
||||||
* the FileName/LineNumber
|
* the FileName/LineNumber
|
||||||
*/
|
*/
|
||||||
class ELuaIHMException : public ELuaWrappedFunctionException
|
class ELuaIHMException : public ELuaWrappedFunctionException
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
static CLuaState *getLuaState();
|
static CLuaState *getLuaState();
|
||||||
public:
|
public:
|
||||||
ELuaIHMException() : ELuaWrappedFunctionException(getLuaState())
|
ELuaIHMException() : ELuaWrappedFunctionException(getLuaState())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -55,24 +59,18 @@ public:
|
||||||
NLMISC_CONVERT_VARGS (reason, format, NLMISC::MaxCStringSize);
|
NLMISC_CONVERT_VARGS (reason, format, NLMISC::MaxCStringSize);
|
||||||
init(getLuaState(), reason);
|
init(getLuaState(), reason);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// ***************************************************************************
|
||||||
// ***************************************************************************
|
/**
|
||||||
#define IHM_LUA_METATABLE "__ui_metatable"
|
|
||||||
#define IHM_LUA_ENVTABLE "__ui_envtable"
|
|
||||||
|
|
||||||
|
|
||||||
// ***************************************************************************
|
|
||||||
/**
|
|
||||||
* Define Functions to export from C to LUA
|
* Define Functions to export from C to LUA
|
||||||
* \author Lionel Berenguier
|
* \author Lionel Berenguier
|
||||||
* \author Nevrax France
|
* \author Nevrax France
|
||||||
* \date 2004
|
* \date 2004
|
||||||
*/
|
*/
|
||||||
class CLuaIHM
|
class CLuaIHM
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static void registerAll(CLuaState &ls);
|
static void registerAll(CLuaState &ls);
|
||||||
|
|
||||||
/** CReflectableInterfaceElement management on stack, stored by a CRefPtr.
|
/** CReflectableInterfaceElement management on stack, stored by a CRefPtr.
|
||||||
|
@ -127,35 +125,27 @@ public:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void registerBasics(CLuaState &ls);
|
static void registerBasics(CLuaState &ls);
|
||||||
static void registerIHM(CLuaState &ls);
|
static void registerIHM(CLuaState &ls);
|
||||||
static void createLuaEnumTable(CLuaState &ls, const std::string &str);
|
static void createLuaEnumTable(CLuaState &ls, const std::string &str);
|
||||||
|
|
||||||
/// \name Exported Functions
|
//////////////////////////////////////////// Exported functions //////////////////////////////////////////////////////
|
||||||
// @{
|
|
||||||
|
|
||||||
// LUA exported Functions with luabind
|
|
||||||
static uint32 getLocalTime();
|
static uint32 getLocalTime();
|
||||||
static double getPreciseLocalTime();
|
static double getPreciseLocalTime();
|
||||||
|
|
||||||
static std::string findReplaceAll(const std::string &str, const std::string &search, const std::string &replace);
|
static std::string findReplaceAll(const std::string &str, const std::string &search, const std::string &replace);
|
||||||
static ucstring findReplaceAll(const ucstring &str, const ucstring &search, const ucstring &replace);
|
static ucstring findReplaceAll(const ucstring &str, const ucstring &search, const ucstring &replace);
|
||||||
// just for ease of use
|
|
||||||
static ucstring findReplaceAll(const ucstring &str, const std::string &search, const std::string &replace);
|
static ucstring findReplaceAll(const ucstring &str, const std::string &search, const std::string &replace);
|
||||||
static ucstring findReplaceAll(const ucstring &str, const std::string &search, const ucstring &replace);
|
static ucstring findReplaceAll(const ucstring &str, const std::string &search, const ucstring &replace);
|
||||||
static ucstring findReplaceAll(const ucstring &str, const ucstring &search, const std::string &replace);
|
static ucstring findReplaceAll(const ucstring &str, const ucstring &search, const std::string &replace);
|
||||||
|
|
||||||
// @}
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// Function export tools
|
|
||||||
// Function to forward lua call to C++ to a 'lua method' exported from a reflected object
|
|
||||||
static int luaMethodCall(lua_State *ls);
|
static int luaMethodCall(lua_State *ls);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif // NL_LUA_IHM_H
|
#endif // NL_LUA_IHM_H
|
||||||
|
|
||||||
|
|
|
@ -22,12 +22,11 @@
|
||||||
namespace NLGUI
|
namespace NLGUI
|
||||||
{
|
{
|
||||||
class CLuaState;
|
class CLuaState;
|
||||||
}
|
|
||||||
|
|
||||||
/// Provides a single global access point to the Lua state, and related stuff. :(
|
/// Provides a single global access point to the Lua state, and related stuff. :(
|
||||||
class CLuaManager
|
class CLuaManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
~CLuaManager();
|
~CLuaManager();
|
||||||
|
|
||||||
static CLuaManager& getInstance()
|
static CLuaManager& getInstance()
|
||||||
|
@ -44,14 +43,15 @@ public:
|
||||||
|
|
||||||
NLGUI::CLuaState* getLuaState() const{ return luaState; }
|
NLGUI::CLuaState* getLuaState() const{ return luaState; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CLuaManager();
|
CLuaManager();
|
||||||
|
|
||||||
static CLuaManager *instance;
|
static CLuaManager *instance;
|
||||||
static bool debugLua;
|
static bool debugLua;
|
||||||
|
|
||||||
NLMISC::CSmartPtr< NLGUI::CLuaState > luaState;
|
NLMISC::CSmartPtr< NLGUI::CLuaState > luaState;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -20,15 +20,14 @@
|
||||||
|
|
||||||
#include "nel/misc/smart_ptr.h"
|
#include "nel/misc/smart_ptr.h"
|
||||||
#include "nel/misc/rgba.h"
|
#include "nel/misc/rgba.h"
|
||||||
//
|
|
||||||
#include "nel/gui/lua_helper.h"
|
#include "nel/gui/lua_helper.h"
|
||||||
using namespace NLGUI;
|
|
||||||
|
|
||||||
|
namespace NLGUI
|
||||||
|
{
|
||||||
|
|
||||||
|
class CLuaEnumeration;
|
||||||
|
|
||||||
class CLuaEnumeration;
|
/**
|
||||||
|
|
||||||
/**
|
|
||||||
* Wrapper to a lua value
|
* Wrapper to a lua value
|
||||||
*
|
*
|
||||||
* Useful to navigate through lua tables without having to deal with the stack.
|
* Useful to navigate through lua tables without having to deal with the stack.
|
||||||
|
@ -48,9 +47,9 @@ class CLuaEnumeration;
|
||||||
*
|
*
|
||||||
* Each reference object has an id giving its path in order to track bugs more easily
|
* Each reference object has an id giving its path in order to track bugs more easily
|
||||||
*/
|
*/
|
||||||
class CLuaObject
|
class CLuaObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CLuaObject() {}
|
CLuaObject() {}
|
||||||
~CLuaObject();
|
~CLuaObject();
|
||||||
// Build this object by popping it from the given lua state
|
// Build this object by popping it from the given lua state
|
||||||
|
@ -171,13 +170,13 @@ public:
|
||||||
bool callNoThrow(int numArgs, int numRet);
|
bool callNoThrow(int numArgs, int numRet);
|
||||||
// Call a method of this table by name (no throw version)
|
// Call a method of this table by name (no throw version)
|
||||||
bool callMethodByNameNoThrow(const char *name, int numArgs, int numRet);
|
bool callMethodByNameNoThrow(const char *name, int numArgs, int numRet);
|
||||||
private:
|
private:
|
||||||
NLMISC::CRefPtr<CLuaState> _LuaState;
|
NLMISC::CRefPtr<CLuaState> _LuaState;
|
||||||
std::string _Id;
|
std::string _Id;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/** enumeration of the content of a lua table
|
/** enumeration of the content of a lua table
|
||||||
*
|
*
|
||||||
* Example of use :
|
* Example of use :
|
||||||
*
|
*
|
||||||
|
@ -208,9 +207,9 @@ private:
|
||||||
\endcode
|
\endcode
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class CLuaEnumeration
|
class CLuaEnumeration
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// is there a next key,value pair in the table
|
// is there a next key,value pair in the table
|
||||||
bool hasNext() { return _HasNext; }
|
bool hasNext() { return _HasNext; }
|
||||||
// Return next key. Assertion if 'hasNext' is false
|
// Return next key. Assertion if 'hasNext' is false
|
||||||
|
@ -219,7 +218,7 @@ public:
|
||||||
CLuaObject &nextValue();
|
CLuaObject &nextValue();
|
||||||
// Go to the next value. Assertion if there's no such value
|
// Go to the next value. Assertion if there's no such value
|
||||||
void next();
|
void next();
|
||||||
private:
|
private:
|
||||||
friend class CLuaObject;
|
friend class CLuaObject;
|
||||||
// current value & key
|
// current value & key
|
||||||
CLuaObject _Table;
|
CLuaObject _Table;
|
||||||
|
@ -229,63 +228,63 @@ private:
|
||||||
bool _HasNext;
|
bool _HasNext;
|
||||||
// construction from a table on the stack
|
// construction from a table on the stack
|
||||||
CLuaEnumeration(CLuaObject &table);
|
CLuaEnumeration(CLuaObject &table);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** macro to ease lua table enumeration
|
/** macro to ease lua table enumeration
|
||||||
* \param object A CLuaObject which must be a table, and on which enumeration is done. An exception will be thrown as 'CLuaObject::enumerate' is
|
* \param object A CLuaObject which must be a table, and on which enumeration is done. An exception will be thrown as 'CLuaObject::enumerate' is
|
||||||
* called if this is not the case
|
* called if this is not the case
|
||||||
* \param enumerator The enumerator object
|
* \param enumerator The enumerator object
|
||||||
*/
|
*/
|
||||||
#define ENUM_LUA_TABLE(object, enumerator) for(CLuaEnumeration enumerator = (object).enumerate(); enumerator.hasNext(); enumerator.next())
|
#define ENUM_LUA_TABLE(object, enumerator) for(CLuaEnumeration enumerator = (object).enumerate(); enumerator.hasNext(); enumerator.next())
|
||||||
|
|
||||||
|
|
||||||
//opitmized lua string for fast comparison
|
//opitmized lua string for fast comparison
|
||||||
class CLuaString
|
class CLuaString
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit CLuaString(const char *value = "")
|
explicit CLuaString(const char *value = "")
|
||||||
{
|
{
|
||||||
nlassert( value != NULL );
|
nlassert( value != NULL );
|
||||||
_Str = value;
|
_Str = value;
|
||||||
}
|
}
|
||||||
const std::string& getStr() const{ return _Str; }
|
const std::string& getStr() const{ return _Str; }
|
||||||
private:
|
private:
|
||||||
std::string _Str;
|
std::string _Str;
|
||||||
mutable CLuaState::TRefPtr _LuaState; // ref ptr so that statics get rebuilt on lua restart
|
mutable CLuaState::TRefPtr _LuaState; // ref ptr so that statics get rebuilt on lua restart
|
||||||
mutable CLuaObject _InLua;
|
mutable CLuaObject _InLua;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool operator==(const char* lh, const CLuaString& rh)
|
inline bool operator==(const char* lh, const CLuaString& rh)
|
||||||
{
|
{
|
||||||
return std::string(lh) == rh.getStr();
|
return std::string(lh) == rh.getStr();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool operator==( const CLuaString& lh, const CLuaString& rh)
|
inline bool operator==( const CLuaString& lh, const CLuaString& rh)
|
||||||
{
|
{
|
||||||
return lh.getStr() == rh.getStr();
|
return lh.getStr() == rh.getStr();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool operator==(const CLuaString& lh, const char* rh)
|
inline bool operator==(const CLuaString& lh, const char* rh)
|
||||||
{
|
{
|
||||||
return std::string(rh) == lh.getStr();
|
return std::string(rh) == lh.getStr();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool operator==( const CLuaString& lh, const std::string& rh)
|
inline bool operator==( const CLuaString& lh, const std::string& rh)
|
||||||
{
|
{
|
||||||
return lh.getStr() == rh;
|
return lh.getStr() == rh;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool operator==(const std::string& lh, const CLuaString& rh)
|
inline bool operator==(const std::string& lh, const CLuaString& rh)
|
||||||
{
|
{
|
||||||
return lh == rh.getStr();
|
return lh == rh.getStr();
|
||||||
}
|
}
|
||||||
|
|
||||||
class CLuaHashMapTraits
|
class CLuaHashMapTraits
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static const size_t bucket_size = 4;
|
static const size_t bucket_size = 4;
|
||||||
static const size_t min_buckets = 8;
|
static const size_t min_buckets = 8;
|
||||||
CLuaHashMapTraits()
|
CLuaHashMapTraits()
|
||||||
|
@ -296,6 +295,9 @@ public:
|
||||||
|
|
||||||
// equality for lua string for hash_map -> they are unique pointer -> compare pointers instead of string content
|
// equality for lua string for hash_map -> they are unique pointer -> compare pointers instead of string content
|
||||||
bool operator()(const char *lhs, const char *rhs) const { return lhs < rhs; }
|
bool operator()(const char *lhs, const char *rhs) const { return lhs < rhs; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -14,30 +14,25 @@
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef CL_REFLECT_H
|
#ifndef CL_REFLECT_H
|
||||||
#define CL_REFLECT_H
|
#define CL_REFLECT_H
|
||||||
|
|
||||||
#include "nel/misc/rgba.h"
|
#include "nel/misc/rgba.h"
|
||||||
#include "nel/gui/lua_object.h"
|
#include "nel/gui/lua_object.h"
|
||||||
//
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class CReflectable;
|
|
||||||
namespace NLGUI
|
namespace NLGUI
|
||||||
{
|
{
|
||||||
|
class CReflectable;
|
||||||
class CLuaState;
|
class CLuaState;
|
||||||
}
|
struct CClassInfo;
|
||||||
struct CClassInfo;
|
|
||||||
|
|
||||||
/** A property of a reflectable object
|
/** A property of a reflectable object
|
||||||
* NB: multiple inheritance not supported
|
* NB: multiple inheritance not supported
|
||||||
*/
|
*/
|
||||||
class CReflectedProperty
|
class CReflectedProperty
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum TType { Boolean = 0,
|
enum TType { Boolean = 0,
|
||||||
SInt32,
|
SInt32,
|
||||||
UInt32,
|
UInt32,
|
||||||
|
@ -66,7 +61,7 @@ public:
|
||||||
//
|
//
|
||||||
typedef int (CReflectable:: *TLuaMethod) (CLuaState &luaState);
|
typedef int (CReflectable:: *TLuaMethod) (CLuaState &luaState);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TType Type;
|
TType Type;
|
||||||
// In each union we have method pointers to retrieve / set the data of the desired type (as told in 'Type')
|
// In each union we have method pointers to retrieve / set the data of the desired type (as told in 'Type')
|
||||||
union
|
union
|
||||||
|
@ -94,20 +89,20 @@ public:
|
||||||
std::string Name;
|
std::string Name;
|
||||||
mutable CLuaObject LuaMethodRef; // cache pointer to function call if type == LuaMethod
|
mutable CLuaObject LuaMethodRef; // cache pointer to function call if type == LuaMethod
|
||||||
const CClassInfo *ParentClass; // filled when 'registerClass' is called
|
const CClassInfo *ParentClass; // filled when 'registerClass' is called
|
||||||
};
|
};
|
||||||
|
|
||||||
// a vector of reflected properties
|
// a vector of reflected properties
|
||||||
typedef std::vector<CReflectedProperty> TReflectedProperties;
|
typedef std::vector<CReflectedProperty> TReflectedProperties;
|
||||||
|
|
||||||
|
|
||||||
struct CClassInfo;
|
struct CClassInfo;
|
||||||
|
|
||||||
/** Base class for a reflectable object
|
/** Base class for a reflectable object
|
||||||
* NB: multiple inheritance not supported
|
* NB: multiple inheritance not supported
|
||||||
*/
|
*/
|
||||||
class CReflectable
|
class CReflectable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~CReflectable() {}
|
virtual ~CReflectable() {}
|
||||||
virtual const char *getReflectedClassName() const { return "CReflectable"; }
|
virtual const char *getReflectedClassName() const { return "CReflectable"; }
|
||||||
virtual const char *getRflectedParentClassName() const { return ""; }
|
virtual const char *getRflectedParentClassName() const { return ""; }
|
||||||
|
@ -127,17 +122,17 @@ public:
|
||||||
* TODO nico : optimized version for lua string (found in CLuaIHM) would maybe fit better here ...
|
* TODO nico : optimized version for lua string (found in CLuaIHM) would maybe fit better here ...
|
||||||
*/
|
*/
|
||||||
const CReflectedProperty *getReflectedProperty(const std::string &propertyName, bool dspWarning= true) const;
|
const CReflectedProperty *getReflectedProperty(const std::string &propertyName, bool dspWarning= true) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CLuaIndexedProperty
|
struct CLuaIndexedProperty
|
||||||
{
|
{
|
||||||
const CReflectedProperty *Prop;
|
const CReflectedProperty *Prop;
|
||||||
CLuaString Id; // must keep id here, so that we are sure the string is not gc in lua and its pointer remains valid
|
CLuaString Id; // must keep id here, so that we are sure the string is not gc in lua and its pointer remains valid
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct CClassInfo
|
struct CClassInfo
|
||||||
{
|
{
|
||||||
TReflectedProperties Properties; // the properties exported by this class
|
TReflectedProperties Properties; // the properties exported by this class
|
||||||
const CClassInfo *ParentClass; // pointer to infos of the parent class, or NULL if it is a root class
|
const CClassInfo *ParentClass; // pointer to infos of the parent class, or NULL if it is a root class
|
||||||
std::string ClassName;
|
std::string ClassName;
|
||||||
|
@ -145,9 +140,9 @@ struct CClassInfo
|
||||||
*/
|
*/
|
||||||
typedef CHashMap<const char *, CLuaIndexedProperty, CLuaHashMapTraits> TLuaStrToPropMap;
|
typedef CHashMap<const char *, CLuaIndexedProperty, CLuaHashMapTraits> TLuaStrToPropMap;
|
||||||
mutable TLuaStrToPropMap LuaStrToProp;
|
mutable TLuaStrToPropMap LuaStrToProp;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Simple reflection system.
|
/** Simple reflection system.
|
||||||
* Used by the GUI and some other objects.
|
* Used by the GUI and some other objects.
|
||||||
* It is used to export some properties so that we can easily manipulate them in the GUI scripts (either lua or with CInterfaceExpr).
|
* It is used to export some properties so that we can easily manipulate them in the GUI scripts (either lua or with CInterfaceExpr).
|
||||||
* NB: multiple inheritance not supported
|
* NB: multiple inheritance not supported
|
||||||
|
@ -178,13 +173,13 @@ struct CClassInfo
|
||||||
* \author Nevrax France
|
* \author Nevrax France
|
||||||
* \date 2002
|
* \date 2002
|
||||||
*/
|
*/
|
||||||
class CReflectSystem
|
class CReflectSystem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef std::map<std::string, CClassInfo> TClassMap;
|
typedef std::map<std::string, CClassInfo> TClassMap;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// release memory
|
// release memory
|
||||||
static void release();
|
static void release();
|
||||||
|
|
||||||
|
@ -199,20 +194,20 @@ public:
|
||||||
// get the list of class for debug or read purpose (NULL if no register has been called)
|
// get the list of class for debug or read purpose (NULL if no register has been called)
|
||||||
static const TClassMap *getClassMap() {return _ClassMap;}
|
static const TClassMap *getClassMap() {return _ClassMap;}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
private:
|
private:
|
||||||
static TClassMap *_ClassMap; // each class and its infos
|
static TClassMap *_ClassMap; // each class and its infos
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/** Helper macros to export properties of a reflectable class
|
/** Helper macros to export properties of a reflectable class
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** Start a declaration of a reflectable class exports
|
/** Start a declaration of a reflectable class exports
|
||||||
* Should be placed inside the class
|
* Should be placed inside the class
|
||||||
*/
|
*/
|
||||||
#define REFLECT_EXPORT_START(className, parentName) \
|
#define REFLECT_EXPORT_START(className, parentName) \
|
||||||
virtual const char *getReflectedClassName() const { return #className; } \
|
virtual const char *getReflectedClassName() const { return #className; } \
|
||||||
virtual const char *getReflectedParentClassName() const { return #parentName; } \
|
virtual const char *getReflectedParentClassName() const { return #parentName; } \
|
||||||
static void getReflectedProperties(TReflectedProperties &props) \
|
static void getReflectedProperties(TReflectedProperties &props) \
|
||||||
|
@ -236,136 +231,138 @@ private:
|
||||||
nlunreferenced(props);
|
nlunreferenced(props);
|
||||||
|
|
||||||
|
|
||||||
// export a boolean value, by giving the name of the get and the set method
|
// export a boolean value, by giving the name of the get and the set method
|
||||||
#define REFLECT_BOOL(exportName, getMethod, setMethod) \
|
#define REFLECT_BOOL(exportName, getMethod, setMethod) \
|
||||||
{ \
|
{ \
|
||||||
CReflectedProperty prop; \
|
CReflectedProperty prop; \
|
||||||
prop.Name = exportName; \
|
prop.Name = exportName; \
|
||||||
prop.Type = CReflectedProperty::Boolean; \
|
prop.Type = CReflectedProperty::Boolean; \
|
||||||
prop.GetMethod.GetBool = (CReflectedProperty::TGetBool) (TGetBoola) &A::getMethod; \
|
prop.GetMethod.GetBool = (CReflectedProperty::TGetBool) (TGetBoola) &A::getMethod; \
|
||||||
prop.SetMethod.SetBool = (CReflectedProperty::TSetBool) (TSetBoola) &A::setMethod; \
|
prop.SetMethod.SetBool = (CReflectedProperty::TSetBool) (TSetBoola) &A::setMethod; \
|
||||||
props.push_back(prop); \
|
props.push_back(prop); \
|
||||||
}
|
}
|
||||||
|
|
||||||
// export a sint32 value, by giving the name of the get and the set method
|
// export a sint32 value, by giving the name of the get and the set method
|
||||||
#define REFLECT_SINT32(exportName, getMethod, setMethod) \
|
#define REFLECT_SINT32(exportName, getMethod, setMethod) \
|
||||||
{ \
|
{ \
|
||||||
CReflectedProperty prop; \
|
CReflectedProperty prop; \
|
||||||
prop.Name = exportName; \
|
prop.Name = exportName; \
|
||||||
prop.Type = CReflectedProperty::SInt32; \
|
prop.Type = CReflectedProperty::SInt32; \
|
||||||
prop.GetMethod.GetSInt32 = (CReflectedProperty::TGetSInt32) (TGetSInt32a) &A::getMethod; \
|
prop.GetMethod.GetSInt32 = (CReflectedProperty::TGetSInt32) (TGetSInt32a) &A::getMethod; \
|
||||||
prop.SetMethod.SetSInt32 = (CReflectedProperty::TSetSInt32) (TSetSInt32a) &A::setMethod; \
|
prop.SetMethod.SetSInt32 = (CReflectedProperty::TSetSInt32) (TSetSInt32a) &A::setMethod; \
|
||||||
props.push_back(prop); \
|
props.push_back(prop); \
|
||||||
}
|
}
|
||||||
|
|
||||||
// export a sint32 value, by giving the name of the get and the set method
|
// export a sint32 value, by giving the name of the get and the set method
|
||||||
#define REFLECT_UINT32(exportName, getMethod, setMethod) \
|
#define REFLECT_UINT32(exportName, getMethod, setMethod) \
|
||||||
{ \
|
{ \
|
||||||
CReflectedProperty prop; \
|
CReflectedProperty prop; \
|
||||||
prop.Name = exportName; \
|
prop.Name = exportName; \
|
||||||
prop.Type = CReflectedProperty::UInt32; \
|
prop.Type = CReflectedProperty::UInt32; \
|
||||||
prop.GetMethod.GetUInt32 = (CReflectedProperty::TGetUInt32) (TGetUInt32a) &A::getMethod; \
|
prop.GetMethod.GetUInt32 = (CReflectedProperty::TGetUInt32) (TGetUInt32a) &A::getMethod; \
|
||||||
prop.SetMethod.SetUInt32 = (CReflectedProperty::TSetUInt32) (TSetUInt32a) &A::setMethod; \
|
prop.SetMethod.SetUInt32 = (CReflectedProperty::TSetUInt32) (TSetUInt32a) &A::setMethod; \
|
||||||
props.push_back(prop); \
|
props.push_back(prop); \
|
||||||
}
|
}
|
||||||
|
|
||||||
// export a float value, by giving the name of the get and the set method
|
// export a float value, by giving the name of the get and the set method
|
||||||
#define REFLECT_FLOAT(exportName, getMethod, setMethod) \
|
#define REFLECT_FLOAT(exportName, getMethod, setMethod) \
|
||||||
{ \
|
{ \
|
||||||
CReflectedProperty prop; \
|
CReflectedProperty prop; \
|
||||||
prop.Name = exportName; \
|
prop.Name = exportName; \
|
||||||
prop.Type = CReflectedProperty::Float; \
|
prop.Type = CReflectedProperty::Float; \
|
||||||
prop.GetMethod.GetFloat = (CReflectedProperty::TGetFloat) (TGetFloata) &A::getMethod; \
|
prop.GetMethod.GetFloat = (CReflectedProperty::TGetFloat) (TGetFloata) &A::getMethod; \
|
||||||
prop.SetMethod.SetFloat = (CReflectedProperty::TSetFloat) (TSetFloata) &A::setMethod; \
|
prop.SetMethod.SetFloat = (CReflectedProperty::TSetFloat) (TSetFloata) &A::setMethod; \
|
||||||
props.push_back(prop); \
|
props.push_back(prop); \
|
||||||
}
|
}
|
||||||
|
|
||||||
// export a string value, by giving the name of the get and the set method
|
// export a string value, by giving the name of the get and the set method
|
||||||
#define REFLECT_STRING(exportName, getMethod, setMethod) \
|
#define REFLECT_STRING(exportName, getMethod, setMethod) \
|
||||||
{ \
|
{ \
|
||||||
CReflectedProperty prop; \
|
CReflectedProperty prop; \
|
||||||
prop.Name = exportName; \
|
prop.Name = exportName; \
|
||||||
prop.Type = CReflectedProperty::String; \
|
prop.Type = CReflectedProperty::String; \
|
||||||
prop.GetMethod.GetString = (CReflectedProperty::TGetString) (TGetStringa) &A::getMethod; \
|
prop.GetMethod.GetString = (CReflectedProperty::TGetString) (TGetStringa) &A::getMethod; \
|
||||||
prop.SetMethod.SetString = (CReflectedProperty::TSetString) (TSetStringa) &A::setMethod; \
|
prop.SetMethod.SetString = (CReflectedProperty::TSetString) (TSetStringa) &A::setMethod; \
|
||||||
props.push_back(prop); \
|
props.push_back(prop); \
|
||||||
}
|
}
|
||||||
|
|
||||||
// export a unicode string value, by giving the name of the get and the set method
|
// export a unicode string value, by giving the name of the get and the set method
|
||||||
#define REFLECT_UCSTRING(exportName, getMethod, setMethod) \
|
#define REFLECT_UCSTRING(exportName, getMethod, setMethod) \
|
||||||
{ \
|
{ \
|
||||||
CReflectedProperty prop; \
|
CReflectedProperty prop; \
|
||||||
prop.Name = exportName; \
|
prop.Name = exportName; \
|
||||||
prop.Type = CReflectedProperty::UCString; \
|
prop.Type = CReflectedProperty::UCString; \
|
||||||
prop.GetMethod.GetUCString = (CReflectedProperty::TGetUCString) (TGetUCStringa) &A::getMethod; \
|
prop.GetMethod.GetUCString = (CReflectedProperty::TGetUCString) (TGetUCStringa) &A::getMethod; \
|
||||||
prop.SetMethod.SetUCString = (CReflectedProperty::TSetUCString) (TSetUCStringa) &A::setMethod; \
|
prop.SetMethod.SetUCString = (CReflectedProperty::TSetUCString) (TSetUCStringa) &A::setMethod; \
|
||||||
props.push_back(prop); \
|
props.push_back(prop); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// export a color value, by giving the name of the get and the set method
|
// export a color value, by giving the name of the get and the set method
|
||||||
#define REFLECT_RGBA(exportName, getMethod, setMethod) \
|
#define REFLECT_RGBA(exportName, getMethod, setMethod) \
|
||||||
{ \
|
{ \
|
||||||
CReflectedProperty prop; \
|
CReflectedProperty prop; \
|
||||||
prop.Name = exportName; \
|
prop.Name = exportName; \
|
||||||
prop.Type = CReflectedProperty::RGBA; \
|
prop.Type = CReflectedProperty::RGBA; \
|
||||||
prop.GetMethod.GetRGBA = (CReflectedProperty::TGetRGBA) (TGetRGBAa) &A::getMethod; \
|
prop.GetMethod.GetRGBA = (CReflectedProperty::TGetRGBA) (TGetRGBAa) &A::getMethod; \
|
||||||
prop.SetMethod.SetRGBA = (CReflectedProperty::TSetRGBA) (TSetRGBAa) &A::setMethod; \
|
prop.SetMethod.SetRGBA = (CReflectedProperty::TSetRGBA) (TSetRGBAa) &A::setMethod; \
|
||||||
props.push_back(prop); \
|
props.push_back(prop); \
|
||||||
}
|
}
|
||||||
|
|
||||||
// export a lua method
|
// export a lua method
|
||||||
#define REFLECT_LUA_METHOD(exportName, method) \
|
#define REFLECT_LUA_METHOD(exportName, method) \
|
||||||
{ \
|
{ \
|
||||||
CReflectedProperty prop; \
|
CReflectedProperty prop; \
|
||||||
prop.Name = exportName; \
|
prop.Name = exportName; \
|
||||||
prop.Type = CReflectedProperty::LuaMethod; \
|
prop.Type = CReflectedProperty::LuaMethod; \
|
||||||
prop.GetMethod.GetLuaMethod = (CReflectedProperty::TLuaMethod) (TLuaMethoda) &A::method; \
|
prop.GetMethod.GetLuaMethod = (CReflectedProperty::TLuaMethod) (TLuaMethoda) &A::method; \
|
||||||
props.push_back(prop); \
|
props.push_back(prop); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ends an export declaration
|
// ends an export declaration
|
||||||
#define REFLECT_EXPORT_END }
|
#define REFLECT_EXPORT_END }
|
||||||
|
|
||||||
|
|
||||||
// This macro registers a reflectable class to the manager
|
// This macro registers a reflectable class to the manager
|
||||||
#define REGISTER_REFLECTABLE_CLASS(className, parentName) \
|
#define REGISTER_REFLECTABLE_CLASS(className, parentName) \
|
||||||
{ \
|
{ \
|
||||||
TReflectedProperties props; \
|
TReflectedProperties props; \
|
||||||
className::getReflectedProperties(props); \
|
className::getReflectedProperties(props); \
|
||||||
CReflectSystem::registerClass(#className, #parentName, props); \
|
CReflectSystem::registerClass(#className, #parentName, props); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** Reflectable refcounted object
|
/** Reflectable refcounted object
|
||||||
* NB nico : added this intermediate class so that the binding from lua to the reflection
|
* NB nico : added this intermediate class so that the binding from lua to the reflection
|
||||||
* system that are found in CLuaIHM can be reused for other objects as well
|
* system that are found in CLuaIHM can be reused for other objects as well
|
||||||
* NOTE: The class is named 'CReflectableRefPtrTarget' and not 'CReflectableRefCount'
|
* NOTE: The class is named 'CReflectableRefPtrTarget' and not 'CReflectableRefCount'
|
||||||
* because the refcount part is only used for ref pointing in the ui
|
* because the refcount part is only used for ref pointing in the ui
|
||||||
*/
|
*/
|
||||||
class CReflectableRefPtrTarget : public CReflectable, public NLMISC::CRefCount
|
class CReflectableRefPtrTarget : public CReflectable, public NLMISC::CRefCount
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~CReflectableRefPtrTarget();
|
virtual ~CReflectableRefPtrTarget();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class CReflectableLuaRef
|
class CReflectableLuaRef
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CReflectableLuaRef(CReflectableRefPtrTarget *ptr = NULL) : Ptr(ptr), _ClassInfo(NULL) {}
|
CReflectableLuaRef(CReflectableRefPtrTarget *ptr = NULL) : Ptr(ptr), _ClassInfo(NULL) {}
|
||||||
NLMISC::CRefPtr<CReflectableRefPtrTarget> Ptr;
|
NLMISC::CRefPtr<CReflectableRefPtrTarget> Ptr;
|
||||||
const CClassInfo &getClassInfo() const;
|
const CClassInfo &getClassInfo() const;
|
||||||
// IMPORTANT : luaStringPtr should have been obtained from lua, see remark in CClassInfo
|
// IMPORTANT : luaStringPtr should have been obtained from lua, see remark in CClassInfo
|
||||||
const CReflectedProperty *getProp(const char *luaStringPtr) const;
|
const CReflectedProperty *getProp(const char *luaStringPtr) const;
|
||||||
private:
|
private:
|
||||||
// cache to class definition of the pointee object (once a CReflectableLuaRef created in lua, it remains a *const* pointer)
|
// cache to class definition of the pointee object (once a CReflectableLuaRef created in lua, it remains a *const* pointer)
|
||||||
mutable const CClassInfo *_ClassInfo;
|
mutable const CClassInfo *_ClassInfo;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
|
|
||||||
|
|
||||||
#include "nel/gui/lua_helper.h"
|
#include "nel/gui/lua_helper.h"
|
||||||
using namespace NLGUI;
|
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
@ -92,8 +91,11 @@ std::ostream &operator<<(std::ostream &str, const ucstring &value)
|
||||||
return str << value.toString();
|
return str << value.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct CMiscFunctions
|
namespace NLGUI
|
||||||
{
|
{
|
||||||
|
|
||||||
|
struct CMiscFunctions
|
||||||
|
{
|
||||||
static std::string fileLookup(const std::string &fileName)
|
static std::string fileLookup(const std::string &fileName)
|
||||||
{
|
{
|
||||||
return NLMISC::CPath::lookup(fileName, false);
|
return NLMISC::CPath::lookup(fileName, false);
|
||||||
|
@ -106,23 +108,23 @@ struct CMiscFunctions
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
bool CLuaIHM::pop(CLuaState &ls, NLMISC::CRGBA &dest)
|
bool CLuaIHM::pop(CLuaState &ls, NLMISC::CRGBA &dest)
|
||||||
{
|
{
|
||||||
//H_AUTO(Lua_CLuaIHM_pop)
|
//H_AUTO(Lua_CLuaIHM_pop)
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (ls.isNil(-1)) return false;
|
if (ls.isNil(-1)) return false;
|
||||||
#if LUABIND_VERSION > 600
|
#if LUABIND_VERSION > 600
|
||||||
luabind::object obj(luabind::from_stack(ls.getStatePointer(), -1));
|
luabind::object obj(luabind::from_stack(ls.getStatePointer(), -1));
|
||||||
ls.pop();
|
ls.pop();
|
||||||
#else
|
#else
|
||||||
luabind::object obj(ls.getStatePointer());
|
luabind::object obj(ls.getStatePointer());
|
||||||
obj.set();
|
obj.set();
|
||||||
#endif
|
#endif
|
||||||
dest = luabind::object_cast<NLMISC::CRGBA>(obj);
|
dest = luabind::object_cast<NLMISC::CRGBA>(obj);
|
||||||
}
|
}
|
||||||
catch(const luabind::cast_failed &)
|
catch(const luabind::cast_failed &)
|
||||||
|
@ -130,22 +132,22 @@ bool CLuaIHM::pop(CLuaState &ls, NLMISC::CRGBA &dest)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
bool CLuaIHM::pop(CLuaState &ls,NLMISC::CVector2f &dest)
|
bool CLuaIHM::pop(CLuaState &ls,NLMISC::CVector2f &dest)
|
||||||
{
|
{
|
||||||
//H_AUTO(Lua_CLuaIHM_pop)
|
//H_AUTO(Lua_CLuaIHM_pop)
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (ls.isNil(-1)) return false;
|
if (ls.isNil(-1)) return false;
|
||||||
#if LUABIND_VERSION > 600
|
#if LUABIND_VERSION > 600
|
||||||
luabind::object obj(luabind::from_stack(ls.getStatePointer(), -1));
|
luabind::object obj(luabind::from_stack(ls.getStatePointer(), -1));
|
||||||
ls.pop();
|
ls.pop();
|
||||||
#else
|
#else
|
||||||
luabind::object obj(ls.getStatePointer());
|
luabind::object obj(ls.getStatePointer());
|
||||||
obj.set();
|
obj.set();
|
||||||
#endif
|
#endif
|
||||||
dest = luabind::object_cast<NLMISC::CVector2f>(obj);
|
dest = luabind::object_cast<NLMISC::CVector2f>(obj);
|
||||||
}
|
}
|
||||||
catch(const luabind::cast_failed &)
|
catch(const luabind::cast_failed &)
|
||||||
|
@ -153,22 +155,22 @@ bool CLuaIHM::pop(CLuaState &ls,NLMISC::CVector2f &dest)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
bool CLuaIHM::pop(CLuaState &ls, ucstring &dest)
|
bool CLuaIHM::pop(CLuaState &ls, ucstring &dest)
|
||||||
{
|
{
|
||||||
//H_AUTO(Lua_CLuaIHM_pop)
|
//H_AUTO(Lua_CLuaIHM_pop)
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (ls.isNil(-1)) return false;
|
if (ls.isNil(-1)) return false;
|
||||||
#if LUABIND_VERSION > 600
|
#if LUABIND_VERSION > 600
|
||||||
luabind::object obj(luabind::from_stack(ls.getStatePointer(), -1));
|
luabind::object obj(luabind::from_stack(ls.getStatePointer(), -1));
|
||||||
ls.pop();
|
ls.pop();
|
||||||
#else
|
#else
|
||||||
luabind::object obj(ls.getStatePointer());
|
luabind::object obj(ls.getStatePointer());
|
||||||
obj.set();
|
obj.set();
|
||||||
#endif
|
#endif
|
||||||
dest = luabind::object_cast<ucstring>(obj);
|
dest = luabind::object_cast<ucstring>(obj);
|
||||||
}
|
}
|
||||||
catch(const luabind::cast_failed &)
|
catch(const luabind::cast_failed &)
|
||||||
|
@ -176,69 +178,71 @@ bool CLuaIHM::pop(CLuaState &ls, ucstring &dest)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
bool CLuaIHM::isUCStringOnStack(CLuaState &ls, sint index)
|
bool CLuaIHM::isUCStringOnStack(CLuaState &ls, sint index)
|
||||||
{
|
{
|
||||||
//H_AUTO(Lua_CLuaIHM_isUCStringOnStack)
|
//H_AUTO(Lua_CLuaIHM_isUCStringOnStack)
|
||||||
ls.pushValue(index);
|
ls.pushValue(index);
|
||||||
ucstring dummy;
|
ucstring dummy;
|
||||||
return pop(ls, dummy);
|
return pop(ls, dummy);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
bool CLuaIHM::getUCStringOnStack(CLuaState &ls, sint index, ucstring &dest)
|
bool CLuaIHM::getUCStringOnStack(CLuaState &ls, sint index, ucstring &dest)
|
||||||
{
|
{
|
||||||
//H_AUTO(Lua_CLuaIHM_getUCStringOnStack)
|
//H_AUTO(Lua_CLuaIHM_getUCStringOnStack)
|
||||||
ls.pushValue(index);
|
ls.pushValue(index);
|
||||||
return pop(ls, dest);
|
return pop(ls, dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
void CLuaIHM::push(CLuaState &ls, const ucstring &value)
|
void CLuaIHM::push(CLuaState &ls, const ucstring &value)
|
||||||
{
|
{
|
||||||
//H_AUTO(Lua_CLuaIHM_push)
|
//H_AUTO(Lua_CLuaIHM_push)
|
||||||
#if LUABIND_VERSION > 600
|
#if LUABIND_VERSION > 600
|
||||||
luabind::detail::push(ls.getStatePointer(), value);
|
luabind::detail::push(ls.getStatePointer(), value);
|
||||||
#else
|
#else
|
||||||
luabind::object obj(ls.getStatePointer(), value);
|
luabind::object obj(ls.getStatePointer(), value);
|
||||||
obj.pushvalue();
|
obj.pushvalue();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
// CInterface To LUA Registry
|
// CInterface To LUA Registry
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
|
|
||||||
|
|
||||||
CLuaState * ELuaIHMException::getLuaState()
|
CLuaState * ELuaIHMException::getLuaState()
|
||||||
{
|
{
|
||||||
return CLuaManager::getInstance().getLuaState();
|
return CLuaManager::getInstance().getLuaState();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
#define LUA_REGISTER_BASIC(_type_) \
|
#define LUA_REGISTER_BASIC(_type_) \
|
||||||
luabind::detail::yes_t is_user_defined(luabind::detail::by_value<_type_>); \
|
luabind::detail::yes_t is_user_defined(luabind::detail::by_value<_type_>); \
|
||||||
_type_ convert_lua_to_cpp(lua_State* L, luabind::detail::by_value<_type_>, int index) \
|
_type_ convert_lua_to_cpp(lua_State* L, luabind::detail::by_value<_type_>, int index) \
|
||||||
{ \
|
{ \
|
||||||
return (_type_)lua_tonumber(L, index); \
|
return (_type_)lua_tonumber(L, index); \
|
||||||
} \
|
} \
|
||||||
int match_lua_to_cpp(lua_State* L, luabind::detail::by_value<_type_>, int index) \
|
int match_lua_to_cpp(lua_State* L, luabind::detail::by_value<_type_>, int index) \
|
||||||
{ \
|
{ \
|
||||||
if (lua_isnumber(L, index)) return 0; else return -1; \
|
if (lua_isnumber(L, index)) return 0; else return -1; \
|
||||||
} \
|
} \
|
||||||
void convert_cpp_to_lua(lua_State* L, const _type_& v) \
|
void convert_cpp_to_lua(lua_State* L, const _type_& v) \
|
||||||
{ \
|
{ \
|
||||||
lua_pushnumber(L, (double)v); \
|
lua_pushnumber(L, (double)v); \
|
||||||
}
|
}
|
||||||
|
|
||||||
// Basic LUA types
|
// Basic LUA types
|
||||||
namespace luabind
|
namespace luabind
|
||||||
{
|
{
|
||||||
namespace converters
|
namespace converters
|
||||||
{
|
{
|
||||||
LUA_REGISTER_BASIC(sint8)
|
LUA_REGISTER_BASIC(sint8)
|
||||||
|
@ -247,14 +251,17 @@ namespace luabind
|
||||||
LUA_REGISTER_BASIC(uint16)
|
LUA_REGISTER_BASIC(uint16)
|
||||||
LUA_REGISTER_BASIC(sint32)
|
LUA_REGISTER_BASIC(sint32)
|
||||||
LUA_REGISTER_BASIC(uint32)
|
LUA_REGISTER_BASIC(uint32)
|
||||||
// LUA_REGISTER_BASIC(sint)
|
// LUA_REGISTER_BASIC(sint)
|
||||||
// LUA_REGISTER_BASIC(uint)
|
// LUA_REGISTER_BASIC(uint)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// ***************************************************************************
|
namespace NLGUI
|
||||||
void CLuaIHM::registerBasics(CLuaState &ls)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// ***************************************************************************
|
||||||
|
void CLuaIHM::registerBasics(CLuaState &ls)
|
||||||
|
{
|
||||||
//H_AUTO(Lua_CLuaIHM_registerBasics)
|
//H_AUTO(Lua_CLuaIHM_registerBasics)
|
||||||
using namespace luabind;
|
using namespace luabind;
|
||||||
lua_State *L= ls.getStatePointer();
|
lua_State *L= ls.getStatePointer();
|
||||||
|
@ -283,7 +290,7 @@ void CLuaIHM::registerBasics(CLuaState &ls)
|
||||||
.def(const_self + other<const std::string>())
|
.def(const_self + other<const std::string>())
|
||||||
.def(other<const std::string>() + const_self)
|
.def(other<const std::string>() + const_self)
|
||||||
// NB nico : luabind crash not solved here -> use concatUCString as a replacement
|
// NB nico : luabind crash not solved here -> use concatUCString as a replacement
|
||||||
// .def(const_self + other<const ucstring &>())
|
// .def(const_self + other<const ucstring &>())
|
||||||
.def(const_self < other<const ucstring&>())
|
.def(const_self < other<const ucstring&>())
|
||||||
.def(const_self == other<const ucstring&>())
|
.def(const_self == other<const ucstring&>())
|
||||||
.def("toUtf8", &ucstring::toUtf8)
|
.def("toUtf8", &ucstring::toUtf8)
|
||||||
|
@ -303,12 +310,12 @@ void CLuaIHM::registerBasics(CLuaState &ls)
|
||||||
.def_readwrite("y", &NLMISC::CVector2f::y)
|
.def_readwrite("y", &NLMISC::CVector2f::y)
|
||||||
];
|
];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
int CLuaIHM::luaMethodCall(lua_State *ls)
|
int CLuaIHM::luaMethodCall(lua_State *ls)
|
||||||
{
|
{
|
||||||
//H_AUTO(Lua_CLuaIHM_luaMethodCall)
|
//H_AUTO(Lua_CLuaIHM_luaMethodCall)
|
||||||
nlassert(ls);
|
nlassert(ls);
|
||||||
const CReflectedProperty *prop = (const CReflectedProperty *) lua_touserdata(ls, lua_upvalueindex(1));
|
const CReflectedProperty *prop = (const CReflectedProperty *) lua_touserdata(ls, lua_upvalueindex(1));
|
||||||
|
@ -351,11 +358,11 @@ int CLuaIHM::luaMethodCall(lua_State *ls)
|
||||||
lua_error(ls);
|
lua_error(ls);
|
||||||
}
|
}
|
||||||
return numResults;
|
return numResults;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
void CLuaIHM::luaValueFromReflectedProperty(CLuaState &ls, CReflectable &reflectedObject, const CReflectedProperty &property)
|
void CLuaIHM::luaValueFromReflectedProperty(CLuaState &ls, CReflectable &reflectedObject, const CReflectedProperty &property)
|
||||||
{
|
{
|
||||||
//H_AUTO(Lua_CLuaIHM_luaValueFromReflectedProperty)
|
//H_AUTO(Lua_CLuaIHM_luaValueFromReflectedProperty)
|
||||||
switch(property.Type)
|
switch(property.Type)
|
||||||
{
|
{
|
||||||
|
@ -374,23 +381,23 @@ void CLuaIHM::luaValueFromReflectedProperty(CLuaState &ls, CReflectable &reflect
|
||||||
case CReflectedProperty::UCString:
|
case CReflectedProperty::UCString:
|
||||||
{
|
{
|
||||||
ucstring str = (reflectedObject.*(property.GetMethod.GetUCString))();
|
ucstring str = (reflectedObject.*(property.GetMethod.GetUCString))();
|
||||||
#if LUABIND_VERSION > 600
|
#if LUABIND_VERSION > 600
|
||||||
luabind::detail::push(ls.getStatePointer(), str);
|
luabind::detail::push(ls.getStatePointer(), str);
|
||||||
#else
|
#else
|
||||||
luabind::object obj(ls.getStatePointer(), str);
|
luabind::object obj(ls.getStatePointer(), str);
|
||||||
obj.pushvalue();
|
obj.pushvalue();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CReflectedProperty::RGBA:
|
case CReflectedProperty::RGBA:
|
||||||
{
|
{
|
||||||
CRGBA color = (reflectedObject.*(property.GetMethod.GetRGBA))();
|
CRGBA color = (reflectedObject.*(property.GetMethod.GetRGBA))();
|
||||||
#if LUABIND_VERSION > 600
|
#if LUABIND_VERSION > 600
|
||||||
luabind::detail::push(ls.getStatePointer(), color);
|
luabind::detail::push(ls.getStatePointer(), color);
|
||||||
#else
|
#else
|
||||||
luabind::object obj(ls.getStatePointer(), color);
|
luabind::object obj(ls.getStatePointer(), color);
|
||||||
obj.pushvalue();
|
obj.pushvalue();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CReflectedProperty::LuaMethod:
|
case CReflectedProperty::LuaMethod:
|
||||||
|
@ -411,14 +418,14 @@ void CLuaIHM::luaValueFromReflectedProperty(CLuaState &ls, CReflectable &reflect
|
||||||
nlstop;
|
nlstop;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static CLuaString lstr_Env("Env");
|
static CLuaString lstr_Env("Env");
|
||||||
static CLuaString lstr_isNil("isNil");
|
static CLuaString lstr_isNil("isNil");
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
void CLuaIHM::luaValueToReflectedProperty(CLuaState &ls, int stackIndex, CReflectable &target, const CReflectedProperty &property) throw(ELuaIHMException)
|
void CLuaIHM::luaValueToReflectedProperty(CLuaState &ls, int stackIndex, CReflectable &target, const CReflectedProperty &property) throw(ELuaIHMException)
|
||||||
{
|
{
|
||||||
//H_AUTO(Lua_property_throw)
|
//H_AUTO(Lua_property_throw)
|
||||||
if(ls.isNil(stackIndex))
|
if(ls.isNil(stackIndex))
|
||||||
throw ELuaIHMException("Trying to set nil to UI property '%s'", property.Name.c_str());
|
throw ELuaIHMException("Trying to set nil to UI property '%s'", property.Name.c_str());
|
||||||
|
@ -492,12 +499,12 @@ void CLuaIHM::luaValueToReflectedProperty(CLuaState &ls, int stackIndex, CReflec
|
||||||
default:
|
default:
|
||||||
nlstop;
|
nlstop;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
void CLuaIHM::createLuaEnumTable(CLuaState &ls, const std::string &str)
|
void CLuaIHM::createLuaEnumTable(CLuaState &ls, const std::string &str)
|
||||||
{
|
{
|
||||||
//H_AUTO(Lua_CLuaIHM_createLuaEnumTable)
|
//H_AUTO(Lua_CLuaIHM_createLuaEnumTable)
|
||||||
std::string path = "", script, p;
|
std::string path = "", script, p;
|
||||||
CSString s = str;
|
CSString s = str;
|
||||||
|
@ -513,9 +520,9 @@ void CLuaIHM::createLuaEnumTable(CLuaState &ls, const std::string &str)
|
||||||
ls.executeScript(script);
|
ls.executeScript(script);
|
||||||
p = s.splitTo('.', true);
|
p = s.splitTo('.', true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define LUABIND_ENUM(__enum__, __name__, __num__, __toStringFunc__) \
|
#define LUABIND_ENUM(__enum__, __name__, __num__, __toStringFunc__) \
|
||||||
createLuaEnumTable(ls, __name__); \
|
createLuaEnumTable(ls, __name__); \
|
||||||
for (uint e=0 ; e<__num__ ; e++) \
|
for (uint e=0 ; e<__num__ ; e++) \
|
||||||
{ \
|
{ \
|
||||||
|
@ -524,11 +531,11 @@ void CLuaIHM::createLuaEnumTable(CLuaState &ls, const std::string &str)
|
||||||
ls.executeScript(temp); \
|
ls.executeScript(temp); \
|
||||||
} \
|
} \
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
#define LUABIND_FUNC(__func__) luabind::def(#__func__, &__func__)
|
#define LUABIND_FUNC(__func__) luabind::def(#__func__, &__func__)
|
||||||
|
|
||||||
void CLuaIHM::registerIHM(CLuaState &ls)
|
void CLuaIHM::registerIHM(CLuaState &ls)
|
||||||
{
|
{
|
||||||
//H_AUTO(Lua_CLuaIHM_registerIHM)
|
//H_AUTO(Lua_CLuaIHM_registerIHM)
|
||||||
CLuaStackChecker lsc(&ls);
|
CLuaStackChecker lsc(&ls);
|
||||||
|
|
||||||
|
@ -581,33 +588,33 @@ void CLuaIHM::registerIHM(CLuaState &ls)
|
||||||
luabind::def("getLocalTime", getLocalTime) // NB : use CLuaIHM::getLocalTime instead of NLMISC::CTime::getLocalTime, because the NLMISC
|
luabind::def("getLocalTime", getLocalTime) // NB : use CLuaIHM::getLocalTime instead of NLMISC::CTime::getLocalTime, because the NLMISC
|
||||||
// version returns a uint64, which can't be casted into lua numbers (doubles ...)
|
// version returns a uint64, which can't be casted into lua numbers (doubles ...)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
double CLuaIHM::getPreciseLocalTime()
|
double CLuaIHM::getPreciseLocalTime()
|
||||||
{
|
{
|
||||||
//H_AUTO(Lua_CLuaIHM_getPreciseLocalTime)
|
//H_AUTO(Lua_CLuaIHM_getPreciseLocalTime)
|
||||||
// don't export these 2 function to lua directly here, because all uint64 can't be represented with lua 'numbers'
|
// don't export these 2 function to lua directly here, because all uint64 can't be represented with lua 'numbers'
|
||||||
return NLMISC::CTime::ticksToSecond(NLMISC::CTime::getPerformanceTime());
|
return NLMISC::CTime::ticksToSecond(NLMISC::CTime::getPerformanceTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
void CLuaIHM::registerAll(CLuaState &ls)
|
void CLuaIHM::registerAll(CLuaState &ls)
|
||||||
{
|
{
|
||||||
//H_AUTO(Lua_CLuaIHM_registerAll)
|
//H_AUTO(Lua_CLuaIHM_registerAll)
|
||||||
registerBasics(ls);
|
registerBasics(ls);
|
||||||
registerIHM(ls);
|
registerIHM(ls);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//#define CHECK_REFLECTABLE_MT
|
//#define CHECK_REFLECTABLE_MT
|
||||||
|
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
void CLuaIHM::pushReflectableOnStack(CLuaState &ls, class CReflectableRefPtrTarget *pRPT)
|
void CLuaIHM::pushReflectableOnStack(CLuaState &ls, class CReflectableRefPtrTarget *pRPT)
|
||||||
{
|
{
|
||||||
//H_AUTO(Lua_CLuaIHM_pushReflectableOnStack)
|
//H_AUTO(Lua_CLuaIHM_pushReflectableOnStack)
|
||||||
nlassert(pRPT);
|
nlassert(pRPT);
|
||||||
CLuaStackChecker lsc(&ls, 1);
|
CLuaStackChecker lsc(&ls, 1);
|
||||||
|
@ -653,7 +660,7 @@ void CLuaIHM::pushReflectableOnStack(CLuaState &ls, class CReflectableRefPtrTa
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that the metatable is correct
|
// Check that the metatable is correct
|
||||||
#ifdef CHECK_REFLECTABLE_MT
|
#ifdef CHECK_REFLECTABLE_MT
|
||||||
nlverify(ls.getMetaTable(-1)); // userdata __ui_metatable
|
nlverify(ls.getMetaTable(-1)); // userdata __ui_metatable
|
||||||
ls.push("__index");
|
ls.push("__index");
|
||||||
ls.getTable(-2);
|
ls.getTable(-2);
|
||||||
|
@ -665,13 +672,13 @@ void CLuaIHM::pushReflectableOnStack(CLuaState &ls, class CReflectableRefPtrTa
|
||||||
nlassert(ls.isCFunction(-2));
|
nlassert(ls.isCFunction(-2));
|
||||||
nlassert(ls.isCFunction(-3));
|
nlassert(ls.isCFunction(-3));
|
||||||
ls.pop(4);
|
ls.pop(4);
|
||||||
#endif
|
#endif
|
||||||
//ls.dumpStack();
|
//ls.dumpStack();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
bool CLuaIHM::isReflectableOnStack(CLuaState &ls, sint index)
|
bool CLuaIHM::isReflectableOnStack(CLuaState &ls, sint index)
|
||||||
{
|
{
|
||||||
//H_AUTO(Lua_CLuaIHM_isReflectableOnStack)
|
//H_AUTO(Lua_CLuaIHM_isReflectableOnStack)
|
||||||
CLuaStackChecker lsc(&ls);
|
CLuaStackChecker lsc(&ls);
|
||||||
|
|
||||||
|
@ -690,11 +697,11 @@ bool CLuaIHM::isReflectableOnStack(CLuaState &ls, sint index)
|
||||||
ls.pop();
|
ls.pop();
|
||||||
|
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
CReflectableRefPtrTarget *CLuaIHM::getReflectableOnStack(CLuaState &ls, sint index)
|
CReflectableRefPtrTarget *CLuaIHM::getReflectableOnStack(CLuaState &ls, sint index)
|
||||||
{
|
{
|
||||||
//H_AUTO(Lua_CLuaIHM_getReflectableOnStack)
|
//H_AUTO(Lua_CLuaIHM_getReflectableOnStack)
|
||||||
if(!isReflectableOnStack(ls, index))
|
if(!isReflectableOnStack(ls, index))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -702,67 +709,67 @@ CReflectableRefPtrTarget *CLuaIHM::getReflectableOnStack(CLuaState &ls, sint
|
||||||
CReflectableLuaRef *p= (CReflectableLuaRef *) ls.toUserData(index);
|
CReflectableLuaRef *p= (CReflectableLuaRef *) ls.toUserData(index);
|
||||||
nlassert(p->Ptr);
|
nlassert(p->Ptr);
|
||||||
return p->Ptr;
|
return p->Ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
// LUA IHM Functions
|
// LUA IHM Functions
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
|
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
uint32 CLuaIHM::getLocalTime()
|
uint32 CLuaIHM::getLocalTime()
|
||||||
{
|
{
|
||||||
//H_AUTO(Lua_CLuaIHM_getLocalTime)
|
//H_AUTO(Lua_CLuaIHM_getLocalTime)
|
||||||
return (uint32) NLMISC::CTime::getLocalTime();
|
return (uint32) NLMISC::CTime::getLocalTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
std::string CLuaIHM::findReplaceAll(const std::string &str, const std::string &search, const std::string &replace)
|
std::string CLuaIHM::findReplaceAll(const std::string &str, const std::string &search, const std::string &replace)
|
||||||
{
|
{
|
||||||
//H_AUTO(Lua_CLuaIHM_findReplaceAll)
|
//H_AUTO(Lua_CLuaIHM_findReplaceAll)
|
||||||
std::string ret= str;
|
std::string ret= str;
|
||||||
while(strFindReplace(ret, search, replace));
|
while(strFindReplace(ret, search, replace));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
ucstring CLuaIHM::findReplaceAll(const ucstring &str, const ucstring &search, const ucstring &replace)
|
ucstring CLuaIHM::findReplaceAll(const ucstring &str, const ucstring &search, const ucstring &replace)
|
||||||
{
|
{
|
||||||
//H_AUTO(Lua_CLuaIHM_findReplaceAll)
|
//H_AUTO(Lua_CLuaIHM_findReplaceAll)
|
||||||
ucstring ret= str;
|
ucstring ret= str;
|
||||||
while(strFindReplace(ret, search, replace));
|
while(strFindReplace(ret, search, replace));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
ucstring CLuaIHM::findReplaceAll(const ucstring &str, const std::string &search, const std::string &replace)
|
ucstring CLuaIHM::findReplaceAll(const ucstring &str, const std::string &search, const std::string &replace)
|
||||||
{
|
{
|
||||||
//H_AUTO(Lua_CLuaIHM_findReplaceAll)
|
//H_AUTO(Lua_CLuaIHM_findReplaceAll)
|
||||||
return findReplaceAll(str, ucstring(search), ucstring(replace));
|
return findReplaceAll(str, ucstring(search), ucstring(replace));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
ucstring CLuaIHM::findReplaceAll(const ucstring &str, const std::string &search, const ucstring &replace)
|
ucstring CLuaIHM::findReplaceAll(const ucstring &str, const std::string &search, const ucstring &replace)
|
||||||
{
|
{
|
||||||
//H_AUTO(Lua_CLuaIHM_findReplaceAll)
|
//H_AUTO(Lua_CLuaIHM_findReplaceAll)
|
||||||
return findReplaceAll(str, ucstring(search), ucstring(replace));
|
return findReplaceAll(str, ucstring(search), ucstring(replace));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
ucstring CLuaIHM::findReplaceAll(const ucstring &str, const ucstring &search, const std::string &replace)
|
ucstring CLuaIHM::findReplaceAll(const ucstring &str, const ucstring &search, const std::string &replace)
|
||||||
{
|
{
|
||||||
//H_AUTO(Lua_CLuaIHM_findReplaceAll)
|
//H_AUTO(Lua_CLuaIHM_findReplaceAll)
|
||||||
return findReplaceAll(str, ucstring(search), ucstring(replace));
|
return findReplaceAll(str, ucstring(search), ucstring(replace));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
void CLuaIHM::fails(CLuaState &ls, const char *format, ...)
|
void CLuaIHM::fails(CLuaState &ls, const char *format, ...)
|
||||||
{
|
{
|
||||||
//H_AUTO(Lua_CLuaIHM_fails)
|
//H_AUTO(Lua_CLuaIHM_fails)
|
||||||
std::string reason;
|
std::string reason;
|
||||||
NLMISC_CONVERT_VARGS (reason, format, NLMISC::MaxCStringSize);
|
NLMISC_CONVERT_VARGS (reason, format, NLMISC::MaxCStringSize);
|
||||||
|
@ -770,52 +777,52 @@ void CLuaIHM::fails(CLuaState &ls, const char *format, ...)
|
||||||
ls.getStackAsString(stack);
|
ls.getStackAsString(stack);
|
||||||
// use a std::exception, to avoid Nel Exception warning
|
// use a std::exception, to avoid Nel Exception warning
|
||||||
throw ELuaIHMException("%s. Lua stack = \n %s", reason.c_str(), stack.c_str());
|
throw ELuaIHMException("%s. Lua stack = \n %s", reason.c_str(), stack.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
void CLuaIHM::checkArgCount(CLuaState &ls, const char* funcName, uint nArgs)
|
void CLuaIHM::checkArgCount(CLuaState &ls, const char* funcName, uint nArgs)
|
||||||
{
|
{
|
||||||
//H_AUTO(Lua_CLuaIHM_checkArgCount)
|
//H_AUTO(Lua_CLuaIHM_checkArgCount)
|
||||||
if(ls.getTop()!=(sint)nArgs)
|
if(ls.getTop()!=(sint)nArgs)
|
||||||
{
|
{
|
||||||
fails(ls, "%s() need exactly %d arguments (tips : check between method & function call)", funcName, nArgs);
|
fails(ls, "%s() need exactly %d arguments (tips : check between method & function call)", funcName, nArgs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
void CLuaIHM::checkArgMin(CLuaState &ls, const char* funcName, uint nArgs)
|
void CLuaIHM::checkArgMin(CLuaState &ls, const char* funcName, uint nArgs)
|
||||||
{
|
{
|
||||||
//H_AUTO(Lua_CLuaIHM_checkArgMin)
|
//H_AUTO(Lua_CLuaIHM_checkArgMin)
|
||||||
if(ls.getTop()<(sint)nArgs)
|
if(ls.getTop()<(sint)nArgs)
|
||||||
{
|
{
|
||||||
fails(ls, "%s() need at least %d arguments (tips : check between method & function call)", funcName, nArgs);
|
fails(ls, "%s() need at least %d arguments (tips : check between method & function call)", funcName, nArgs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
void CLuaIHM::checkArgMax(CLuaState &ls,const char* funcName,uint nArgs)
|
void CLuaIHM::checkArgMax(CLuaState &ls,const char* funcName,uint nArgs)
|
||||||
{
|
{
|
||||||
//H_AUTO(Lua_CLuaIHM_checkArgMax)
|
//H_AUTO(Lua_CLuaIHM_checkArgMax)
|
||||||
if(ls.getTop()>(sint)nArgs)
|
if(ls.getTop()>(sint)nArgs)
|
||||||
{
|
{
|
||||||
fails(ls, "%s() need at most %d arguments.", funcName, nArgs);
|
fails(ls, "%s() need at most %d arguments.", funcName, nArgs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
void CLuaIHM::check(CLuaState &ls, bool ok, const std::string &failReason)
|
void CLuaIHM::check(CLuaState &ls, bool ok, const std::string &failReason)
|
||||||
{
|
{
|
||||||
//H_AUTO(Lua_CLuaIHM_check)
|
//H_AUTO(Lua_CLuaIHM_check)
|
||||||
if(!ok)
|
if(!ok)
|
||||||
{
|
{
|
||||||
fails(ls, failReason.c_str());
|
fails(ls, failReason.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
void CLuaIHM::checkArgType(CLuaState &ls, const char *funcName, uint index, int argType)
|
void CLuaIHM::checkArgType(CLuaState &ls, const char *funcName, uint index, int argType)
|
||||||
{
|
{
|
||||||
//H_AUTO(Lua_CLuaIHM_checkArgType)
|
//H_AUTO(Lua_CLuaIHM_checkArgType)
|
||||||
nlassert(index > 0);
|
nlassert(index > 0);
|
||||||
if (ls.getTop() < (int) index)
|
if (ls.getTop() < (int) index)
|
||||||
|
@ -826,11 +833,11 @@ void CLuaIHM::checkArgType(CLuaState &ls, const char *funcName, uint index,
|
||||||
{
|
{
|
||||||
fails(ls, "%s : argument %d of expected type %s has bad type : %s", funcName, index, ls.getTypename(argType), ls.getTypename(ls.type(index)), ls.type(index));
|
fails(ls, "%s : argument %d of expected type %s has bad type : %s", funcName, index, ls.getTypename(argType), ls.getTypename(ls.type(index)), ls.type(index));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
void CLuaIHM::checkArgTypeRGBA(CLuaState &ls, const char *funcName, uint index)
|
void CLuaIHM::checkArgTypeRGBA(CLuaState &ls, const char *funcName, uint index)
|
||||||
{
|
{
|
||||||
//H_AUTO(Lua_CLuaIHM_checkArgTypeRGBA)
|
//H_AUTO(Lua_CLuaIHM_checkArgTypeRGBA)
|
||||||
nlassert(index > 0);
|
nlassert(index > 0);
|
||||||
if (ls.getTop() < (int) index)
|
if (ls.getTop() < (int) index)
|
||||||
|
@ -843,11 +850,11 @@ void CLuaIHM::checkArgTypeRGBA(CLuaState &ls, const char *funcName, uint index)
|
||||||
{
|
{
|
||||||
fails(ls, "%s : argument %d of expected type RGBA has bad type : %s", funcName, index, ls.getTypename(ls.type(index)), ls.type(index));
|
fails(ls, "%s : argument %d of expected type RGBA has bad type : %s", funcName, index, ls.getTypename(ls.type(index)), ls.type(index));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
void CLuaIHM::checkArgTypeUCString(CLuaState &ls, const char *funcName, uint index)
|
void CLuaIHM::checkArgTypeUCString(CLuaState &ls, const char *funcName, uint index)
|
||||||
{
|
{
|
||||||
//H_AUTO(Lua_CLuaIHM_checkArgTypeUCString)
|
//H_AUTO(Lua_CLuaIHM_checkArgTypeUCString)
|
||||||
nlassert(index > 0);
|
nlassert(index > 0);
|
||||||
if (ls.getTop() < (int) index)
|
if (ls.getTop() < (int) index)
|
||||||
|
@ -860,23 +867,23 @@ void CLuaIHM::checkArgTypeUCString(CLuaState &ls, const char *funcName, uint ind
|
||||||
{
|
{
|
||||||
fails(ls, "%s : argument %d of expected type ucstring has bad type : %s", funcName, index, ls.getTypename(ls.type(index)), ls.type(index));
|
fails(ls, "%s : argument %d of expected type ucstring has bad type : %s", funcName, index, ls.getTypename(ls.type(index)), ls.type(index));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
bool CLuaIHM::popString(CLuaState &ls, std::string & dest)
|
bool CLuaIHM::popString(CLuaState &ls, std::string & dest)
|
||||||
{
|
{
|
||||||
//H_AUTO(Lua_CLuaIHM_popString)
|
//H_AUTO(Lua_CLuaIHM_popString)
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
#if LUABIND_VERSION > 600
|
#if LUABIND_VERSION > 600
|
||||||
luabind::object obj(luabind::from_stack(ls.getStatePointer(), -1));
|
luabind::object obj(luabind::from_stack(ls.getStatePointer(), -1));
|
||||||
ls.pop();
|
ls.pop();
|
||||||
#else
|
#else
|
||||||
luabind::object obj(ls.getStatePointer());
|
luabind::object obj(ls.getStatePointer());
|
||||||
obj.set();
|
obj.set();
|
||||||
#endif
|
#endif
|
||||||
dest = luabind::object_cast<std::string>(obj);
|
dest = luabind::object_cast<std::string>(obj);
|
||||||
}
|
}
|
||||||
catch(const luabind::cast_failed &)
|
catch(const luabind::cast_failed &)
|
||||||
|
@ -884,21 +891,21 @@ bool CLuaIHM::popString(CLuaState &ls, std::string & dest)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
bool CLuaIHM::popSINT32(CLuaState &ls, sint32 & dest)
|
bool CLuaIHM::popSINT32(CLuaState &ls, sint32 & dest)
|
||||||
{
|
{
|
||||||
//H_AUTO(Lua_CLuaIHM_popSINT32)
|
//H_AUTO(Lua_CLuaIHM_popSINT32)
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
#if LUABIND_VERSION > 600
|
#if LUABIND_VERSION > 600
|
||||||
luabind::object obj(luabind::from_stack(ls.getStatePointer(), -1));
|
luabind::object obj(luabind::from_stack(ls.getStatePointer(), -1));
|
||||||
ls.pop();
|
ls.pop();
|
||||||
#else
|
#else
|
||||||
luabind::object obj(ls.getStatePointer());
|
luabind::object obj(ls.getStatePointer());
|
||||||
obj.set();
|
obj.set();
|
||||||
#endif
|
#endif
|
||||||
dest = luabind::object_cast<sint32>(obj);
|
dest = luabind::object_cast<sint32>(obj);
|
||||||
}
|
}
|
||||||
catch(const luabind::cast_failed &)
|
catch(const luabind::cast_failed &)
|
||||||
|
@ -906,11 +913,11 @@ bool CLuaIHM::popSINT32(CLuaState &ls, sint32 & dest)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
void CLuaIHM::getPoly2DOnStack(CLuaState &ls, sint index, NLMISC::CPolygon2D &dest)
|
void CLuaIHM::getPoly2DOnStack(CLuaState &ls, sint index, NLMISC::CPolygon2D &dest)
|
||||||
{
|
{
|
||||||
//H_AUTO(Lua_CLuaIHM_getPoly2DOnStack)
|
//H_AUTO(Lua_CLuaIHM_getPoly2DOnStack)
|
||||||
ls.pushValue(index);
|
ls.pushValue(index);
|
||||||
CLuaObject poly;
|
CLuaObject poly;
|
||||||
|
@ -926,6 +933,6 @@ void CLuaIHM::getPoly2DOnStack(CLuaState &ls, sint index, NLMISC::CPolygon2D &de
|
||||||
}
|
}
|
||||||
dest.Vertices.push_back(pos);
|
dest.Vertices.push_back(pos);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,17 +18,22 @@
|
||||||
#include "nel/gui/lua_manager.h"
|
#include "nel/gui/lua_manager.h"
|
||||||
#include "nel/gui/lua_helper.h"
|
#include "nel/gui/lua_helper.h"
|
||||||
|
|
||||||
bool CLuaManager::debugLua = false;
|
namespace NLGUI
|
||||||
CLuaManager* CLuaManager::instance = NULL;
|
|
||||||
|
|
||||||
CLuaManager::CLuaManager()
|
|
||||||
{
|
{
|
||||||
|
|
||||||
|
bool CLuaManager::debugLua = false;
|
||||||
|
CLuaManager* CLuaManager::instance = NULL;
|
||||||
|
|
||||||
|
CLuaManager::CLuaManager()
|
||||||
|
{
|
||||||
luaState = new NLGUI::CLuaState( debugLua );
|
luaState = new NLGUI::CLuaState( debugLua );
|
||||||
}
|
}
|
||||||
|
|
||||||
CLuaManager::~CLuaManager()
|
CLuaManager::~CLuaManager()
|
||||||
{
|
{
|
||||||
luaState = NULL;
|
luaState = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -14,47 +14,41 @@
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
//#include "stdpch.h"
|
|
||||||
#include "nel/gui/lua_object.h"
|
#include "nel/gui/lua_object.h"
|
||||||
#include "nel/gui/lua_ihm.h"
|
#include "nel/gui/lua_ihm.h"
|
||||||
//#include "lua_ihm_ryzom.h"
|
|
||||||
#include "nel/gui/lua_helper.h"
|
#include "nel/gui/lua_helper.h"
|
||||||
using namespace NLGUI;
|
|
||||||
//
|
|
||||||
//#include "interface_manager.h"
|
|
||||||
|
|
||||||
////////////////
|
namespace NLGUI
|
||||||
// CLuaObject //
|
|
||||||
////////////////
|
|
||||||
|
|
||||||
// *************************************************
|
|
||||||
CLuaObject::CLuaObject(CLuaState &state, const char *id)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// *************************************************
|
||||||
|
CLuaObject::CLuaObject(CLuaState &state, const char *id)
|
||||||
|
{
|
||||||
pop(state, id);
|
pop(state, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************
|
// *************************************************
|
||||||
CLuaObject::CLuaObject(CLuaState &state, const std::string &id)
|
CLuaObject::CLuaObject(CLuaState &state, const std::string &id)
|
||||||
{
|
{
|
||||||
pop(state, id.c_str());
|
pop(state, id.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// *************************************************
|
// *************************************************
|
||||||
bool CLuaObject::isValid() const
|
bool CLuaObject::isValid() const
|
||||||
{
|
{
|
||||||
return getLuaState() != NULL;
|
return getLuaState() != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************
|
// *************************************************
|
||||||
CLuaState *CLuaObject::getLuaState() const
|
CLuaState *CLuaObject::getLuaState() const
|
||||||
{
|
{
|
||||||
return _LuaState;
|
return _LuaState;
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************
|
// *************************************************
|
||||||
CLuaObject::CLuaObject(const CLuaObject &other)
|
CLuaObject::CLuaObject(const CLuaObject &other)
|
||||||
{
|
{
|
||||||
if (other.isValid())
|
if (other.isValid())
|
||||||
{
|
{
|
||||||
other.push();
|
other.push();
|
||||||
|
@ -63,11 +57,11 @@ CLuaObject::CLuaObject(const CLuaObject &other)
|
||||||
_Id = other._Id;
|
_Id = other._Id;
|
||||||
}
|
}
|
||||||
// else ... copy of an invalid CLuaObject( is an invalid CLuaObject
|
// else ... copy of an invalid CLuaObject( is an invalid CLuaObject
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************
|
// *************************************************
|
||||||
CLuaObject &CLuaObject::operator=(const CLuaObject &other)
|
CLuaObject &CLuaObject::operator=(const CLuaObject &other)
|
||||||
{
|
{
|
||||||
if (!other.isValid())
|
if (!other.isValid())
|
||||||
{
|
{
|
||||||
release();
|
release();
|
||||||
|
@ -77,28 +71,28 @@ CLuaObject &CLuaObject::operator=(const CLuaObject &other)
|
||||||
pop(*other.getLuaState());
|
pop(*other.getLuaState());
|
||||||
_Id = other._Id;
|
_Id = other._Id;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************
|
// *************************************************
|
||||||
bool CLuaObject::rawEqual(const CLuaObject &other) const
|
bool CLuaObject::rawEqual(const CLuaObject &other) const
|
||||||
{
|
{
|
||||||
nlassert(other.getLuaState() == getLuaState());
|
nlassert(other.getLuaState() == getLuaState());
|
||||||
push();
|
push();
|
||||||
other.push();
|
other.push();
|
||||||
bool equal = other.getLuaState()->rawEqual(-1, -2);
|
bool equal = other.getLuaState()->rawEqual(-1, -2);
|
||||||
getLuaState()->pop(2);
|
getLuaState()->pop(2);
|
||||||
return equal;
|
return equal;
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************
|
// *************************************************
|
||||||
CLuaObject::~CLuaObject()
|
CLuaObject::~CLuaObject()
|
||||||
{
|
{
|
||||||
release();
|
release();
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************
|
// *************************************************
|
||||||
void CLuaObject::release()
|
void CLuaObject::release()
|
||||||
{
|
{
|
||||||
if (_LuaState)
|
if (_LuaState)
|
||||||
{
|
{
|
||||||
CLuaStackChecker lsc(_LuaState);
|
CLuaStackChecker lsc(_LuaState);
|
||||||
|
@ -107,11 +101,11 @@ void CLuaObject::release()
|
||||||
_LuaState->setTable(LUA_REGISTRYINDEX);
|
_LuaState->setTable(LUA_REGISTRYINDEX);
|
||||||
_LuaState = NULL;
|
_LuaState = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************
|
// *************************************************
|
||||||
void CLuaObject::pop(CLuaState &luaState, const char *id)
|
void CLuaObject::pop(CLuaState &luaState, const char *id)
|
||||||
{
|
{
|
||||||
release();
|
release();
|
||||||
nlassert(luaState.getTop() >= 1);
|
nlassert(luaState.getTop() >= 1);
|
||||||
{
|
{
|
||||||
|
@ -123,68 +117,68 @@ void CLuaObject::pop(CLuaState &luaState, const char *id)
|
||||||
luaState.pop();
|
luaState.pop();
|
||||||
_LuaState = &luaState;
|
_LuaState = &luaState;
|
||||||
_Id = id;
|
_Id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************
|
// *************************************************
|
||||||
void CLuaObject::push() const
|
void CLuaObject::push() const
|
||||||
{
|
{
|
||||||
nlassert(isValid());
|
nlassert(isValid());
|
||||||
_LuaState->pushLightUserData((void *) this);
|
_LuaState->pushLightUserData((void *) this);
|
||||||
_LuaState->getTable(LUA_REGISTRYINDEX);
|
_LuaState->getTable(LUA_REGISTRYINDEX);
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************
|
// *************************************************
|
||||||
int CLuaObject::type() const
|
int CLuaObject::type() const
|
||||||
{
|
{
|
||||||
push();
|
push();
|
||||||
int type = _LuaState->type();
|
int type = _LuaState->type();
|
||||||
_LuaState->pop();
|
_LuaState->pop();
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************
|
// *************************************************
|
||||||
const char *CLuaObject::getTypename() const
|
const char *CLuaObject::getTypename() const
|
||||||
{
|
{
|
||||||
push();
|
push();
|
||||||
const char *typeName = _LuaState->getTypename(-1);
|
const char *typeName = _LuaState->getTypename(-1);
|
||||||
_LuaState->pop();
|
_LuaState->pop();
|
||||||
return typeName;
|
return typeName;
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************
|
// *************************************************
|
||||||
bool CLuaObject::isNil() const { push(); bool result = _LuaState->isNil(); _LuaState->pop(); return result; }
|
bool CLuaObject::isNil() const { push(); bool result = _LuaState->isNil(); _LuaState->pop(); return result; }
|
||||||
bool CLuaObject::isNumber() const { push(); bool result = _LuaState->isNumber(); _LuaState->pop(); return result; }
|
bool CLuaObject::isNumber() const { push(); bool result = _LuaState->isNumber(); _LuaState->pop(); return result; }
|
||||||
bool CLuaObject::isBoolean() const { push(); bool result = _LuaState->isBoolean(); _LuaState->pop(); return result; }
|
bool CLuaObject::isBoolean() const { push(); bool result = _LuaState->isBoolean(); _LuaState->pop(); return result; }
|
||||||
bool CLuaObject::isString() const { push(); bool result = _LuaState->isString(); _LuaState->pop(); return result; }
|
bool CLuaObject::isString() const { push(); bool result = _LuaState->isString(); _LuaState->pop(); return result; }
|
||||||
bool CLuaObject::isFunction() const { push(); bool result = _LuaState->isFunction(); _LuaState->pop(); return result; }
|
bool CLuaObject::isFunction() const { push(); bool result = _LuaState->isFunction(); _LuaState->pop(); return result; }
|
||||||
bool CLuaObject::isCFunction() const { push(); bool result = _LuaState->isCFunction(); _LuaState->pop(); return result; }
|
bool CLuaObject::isCFunction() const { push(); bool result = _LuaState->isCFunction(); _LuaState->pop(); return result; }
|
||||||
bool CLuaObject::isTable() const { push(); bool result = _LuaState->isTable(); _LuaState->pop(); return result; }
|
bool CLuaObject::isTable() const { push(); bool result = _LuaState->isTable(); _LuaState->pop(); return result; }
|
||||||
bool CLuaObject::isUserData() const { push(); bool result = _LuaState->isUserData(); _LuaState->pop(); return result; }
|
bool CLuaObject::isUserData() const { push(); bool result = _LuaState->isUserData(); _LuaState->pop(); return result; }
|
||||||
bool CLuaObject::isLightUserData() const { push(); bool result = _LuaState->isLightUserData(); _LuaState->pop(); return result; }
|
bool CLuaObject::isLightUserData() const { push(); bool result = _LuaState->isLightUserData(); _LuaState->pop(); return result; }
|
||||||
bool CLuaObject::isRGBA() const
|
bool CLuaObject::isRGBA() const
|
||||||
{
|
{
|
||||||
if (!isUserData()) return false;
|
if (!isUserData()) return false;
|
||||||
push();
|
push();
|
||||||
NLMISC::CRGBA dummy;
|
NLMISC::CRGBA dummy;
|
||||||
return CLuaIHM::pop(*_LuaState, dummy);
|
return CLuaIHM::pop(*_LuaState, dummy);
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************
|
// *************************************************
|
||||||
bool CLuaObject::toBoolean() const { push(); bool result = _LuaState->toBoolean(); _LuaState->pop(); return result; }
|
bool CLuaObject::toBoolean() const { push(); bool result = _LuaState->toBoolean(); _LuaState->pop(); return result; }
|
||||||
lua_Number CLuaObject::toNumber() const { push(); lua_Number result = _LuaState->toNumber(); _LuaState->pop(); return result; }
|
lua_Number CLuaObject::toNumber() const { push(); lua_Number result = _LuaState->toNumber(); _LuaState->pop(); return result; }
|
||||||
std::string CLuaObject::toString() const
|
std::string CLuaObject::toString() const
|
||||||
{
|
{
|
||||||
push();
|
push();
|
||||||
const char *str = _LuaState->toString();
|
const char *str = _LuaState->toString();
|
||||||
std::string result = str ? str : "";
|
std::string result = str ? str : "";
|
||||||
_LuaState->pop();
|
_LuaState->pop();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
lua_CFunction CLuaObject::toCFunction() const { push(); lua_CFunction result = _LuaState->toCFunction(); _LuaState->pop(); return result; }
|
lua_CFunction CLuaObject::toCFunction() const { push(); lua_CFunction result = _LuaState->toCFunction(); _LuaState->pop(); return result; }
|
||||||
void *CLuaObject::toUserData() const { push(); void *result = _LuaState->toUserData(); _LuaState->pop(); return result; }
|
void *CLuaObject::toUserData() const { push(); void *result = _LuaState->toUserData(); _LuaState->pop(); return result; }
|
||||||
const void *CLuaObject::toPointer() const { push(); const void *result = _LuaState->toPointer(); _LuaState->pop(); return result; }
|
const void *CLuaObject::toPointer() const { push(); const void *result = _LuaState->toPointer(); _LuaState->pop(); return result; }
|
||||||
NLMISC::CRGBA CLuaObject::toRGBA() const
|
NLMISC::CRGBA CLuaObject::toRGBA() const
|
||||||
{
|
{
|
||||||
NLMISC::CRGBA result;
|
NLMISC::CRGBA result;
|
||||||
push();
|
push();
|
||||||
if (CLuaIHM::pop(*_LuaState, result))
|
if (CLuaIHM::pop(*_LuaState, result))
|
||||||
|
@ -192,18 +186,18 @@ NLMISC::CRGBA CLuaObject::toRGBA() const
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
return NLMISC::CRGBA::Black;
|
return NLMISC::CRGBA::Black;
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************
|
// *************************************************
|
||||||
CLuaObject::operator bool() const { return toBoolean(); }
|
CLuaObject::operator bool() const { return toBoolean(); }
|
||||||
CLuaObject::operator float() const { return (float) toNumber(); }
|
CLuaObject::operator float() const { return (float) toNumber(); }
|
||||||
CLuaObject::operator double() const { return (double) toNumber(); }
|
CLuaObject::operator double() const { return (double) toNumber(); }
|
||||||
CLuaObject::operator std::string() const { return toString(); }
|
CLuaObject::operator std::string() const { return toString(); }
|
||||||
|
|
||||||
|
|
||||||
// *************************************************
|
// *************************************************
|
||||||
bool CLuaObject::isEnumerable() const
|
bool CLuaObject::isEnumerable() const
|
||||||
{
|
{
|
||||||
if (isTable()) return true;
|
if (isTable()) return true;
|
||||||
CLuaStackRestorer lsr(_LuaState, _LuaState->getTop());
|
CLuaStackRestorer lsr(_LuaState, _LuaState->getTop());
|
||||||
push();
|
push();
|
||||||
|
@ -215,21 +209,21 @@ bool CLuaObject::isEnumerable() const
|
||||||
return _LuaState->isFunction();
|
return _LuaState->isFunction();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************
|
// *************************************************
|
||||||
CLuaEnumeration CLuaObject::enumerate() throw(ELuaNotATable)
|
CLuaEnumeration CLuaObject::enumerate() throw(ELuaNotATable)
|
||||||
{
|
{
|
||||||
if (!isEnumerable())
|
if (!isEnumerable())
|
||||||
{
|
{
|
||||||
throw ELuaNotATable(NLMISC::toString("Called CLuaObject::enumerate on an object that has no enumeration (not a table or no '__next' method in the metatable). Object is '%s' with type '%s'", getId().c_str(), getTypename()).c_str());
|
throw ELuaNotATable(NLMISC::toString("Called CLuaObject::enumerate on an object that has no enumeration (not a table or no '__next' method in the metatable). Object is '%s' with type '%s'", getId().c_str(), getTypename()).c_str());
|
||||||
}
|
}
|
||||||
return CLuaEnumeration(*this);
|
return CLuaEnumeration(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************
|
// *************************************************
|
||||||
CLuaObject CLuaObject::operator[](const char *key) const
|
CLuaObject CLuaObject::operator[](const char *key) const
|
||||||
{
|
{
|
||||||
nlassert(key);
|
nlassert(key);
|
||||||
nlassert(isValid());
|
nlassert(isValid());
|
||||||
if (!isEnumerable())
|
if (!isEnumerable())
|
||||||
|
@ -245,11 +239,11 @@ CLuaObject CLuaObject::operator[](const char *key) const
|
||||||
CLuaObject subObject(*_LuaState, concatId(getId(), key));
|
CLuaObject subObject(*_LuaState, concatId(getId(), key));
|
||||||
_LuaState->pop(); // pop the sub object
|
_LuaState->pop(); // pop the sub object
|
||||||
return subObject;
|
return subObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************
|
// *************************************************
|
||||||
CLuaObject CLuaObject::operator[](double key) const
|
CLuaObject CLuaObject::operator[](double key) const
|
||||||
{
|
{
|
||||||
nlassert(isValid());
|
nlassert(isValid());
|
||||||
if (!isEnumerable())
|
if (!isEnumerable())
|
||||||
{
|
{
|
||||||
|
@ -264,26 +258,26 @@ CLuaObject CLuaObject::operator[](double key) const
|
||||||
CLuaObject subObject(*_LuaState, concatId(getId(), NLMISC::toString(key)));
|
CLuaObject subObject(*_LuaState, concatId(getId(), NLMISC::toString(key)));
|
||||||
_LuaState->pop(); // pop the sub object
|
_LuaState->pop(); // pop the sub object
|
||||||
return subObject;
|
return subObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************
|
// *************************************************
|
||||||
CLuaObject CLuaObject::at(const char *key) const throw(ELuaNotATable)
|
CLuaObject CLuaObject::at(const char *key) const throw(ELuaNotATable)
|
||||||
{
|
{
|
||||||
if (!isEnumerable()) throw ELuaNotATable(NLMISC::toString("Can't get key '%s' in object '%s' because type is '%s', it is not a table.", key, getId().c_str(), getTypename()).c_str());
|
if (!isEnumerable()) throw ELuaNotATable(NLMISC::toString("Can't get key '%s' in object '%s' because type is '%s', it is not a table.", key, getId().c_str(), getTypename()).c_str());
|
||||||
return operator[](key);
|
return operator[](key);
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************
|
// *************************************************
|
||||||
bool CLuaObject::hasKey(const char *key) const
|
bool CLuaObject::hasKey(const char *key) const
|
||||||
{
|
{
|
||||||
if (!isEnumerable()) throw ELuaNotATable(NLMISC::toString("Trying to access key '%s' on object '%s' of type %s.", key, getId().c_str(), getTypename()).c_str());
|
if (!isEnumerable()) throw ELuaNotATable(NLMISC::toString("Trying to access key '%s' on object '%s' of type %s.", key, getId().c_str(), getTypename()).c_str());
|
||||||
CLuaObject value = operator[](key);
|
CLuaObject value = operator[](key);
|
||||||
return (!value.isNil());
|
return (!value.isNil());
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************
|
// *************************************************
|
||||||
CLuaObject CLuaObject::newTable(const char *tableName) throw(ELuaNotATable)
|
CLuaObject CLuaObject::newTable(const char *tableName) throw(ELuaNotATable)
|
||||||
{
|
{
|
||||||
nlassert(tableName);
|
nlassert(tableName);
|
||||||
nlassert(isValid());
|
nlassert(isValid());
|
||||||
if (!isTable()) throw ELuaNotATable(NLMISC::toString("Trying to create a subtable '%s' on object '%s' of type %s (not a table).", tableName, getId().c_str(), getTypename()));
|
if (!isTable()) throw ELuaNotATable(NLMISC::toString("Trying to create a subtable '%s' on object '%s' of type %s (not a table).", tableName, getId().c_str(), getTypename()));
|
||||||
|
@ -294,11 +288,11 @@ CLuaObject CLuaObject::newTable(const char *tableName) throw(ELuaNotATable)
|
||||||
_LuaState->setTable(-3);
|
_LuaState->setTable(-3);
|
||||||
_LuaState->pop();
|
_LuaState->pop();
|
||||||
return at(tableName); //\TODO nico double copy here ...
|
return at(tableName); //\TODO nico double copy here ...
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************
|
// *************************************************
|
||||||
void CLuaObject::setValue(const char *key, const CLuaObject &value) throw(ELuaNotATable)
|
void CLuaObject::setValue(const char *key, const CLuaObject &value) throw(ELuaNotATable)
|
||||||
{
|
{
|
||||||
nlassert(key);
|
nlassert(key);
|
||||||
nlassert(isValid());
|
nlassert(isValid());
|
||||||
nlassert(value.isValid());
|
nlassert(value.isValid());
|
||||||
|
@ -310,11 +304,11 @@ void CLuaObject::setValue(const char *key, const CLuaObject &value) throw(ELuaN
|
||||||
value.push();
|
value.push();
|
||||||
_LuaState->setTable(-3);
|
_LuaState->setTable(-3);
|
||||||
_LuaState->pop();
|
_LuaState->pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************
|
// *************************************************
|
||||||
void CLuaObject::setNil(const char *key) throw(ELuaNotATable)
|
void CLuaObject::setNil(const char *key) throw(ELuaNotATable)
|
||||||
{
|
{
|
||||||
nlassert(key);
|
nlassert(key);
|
||||||
nlassert(isValid());
|
nlassert(isValid());
|
||||||
if (!isTable()) throw ELuaNotATable(NLMISC::toString("Trying to set a value 'nil' at key %s on object '%s' of type %s (not a table).", key, getId().c_str(), getTypename()));
|
if (!isTable()) throw ELuaNotATable(NLMISC::toString("Trying to set a value 'nil' at key %s on object '%s' of type %s (not a table).", key, getId().c_str(), getTypename()));
|
||||||
|
@ -324,11 +318,11 @@ void CLuaObject::setNil(const char *key) throw(ELuaNotATable)
|
||||||
_LuaState->pushNil();
|
_LuaState->pushNil();
|
||||||
_LuaState->setTable(-3);
|
_LuaState->setTable(-3);
|
||||||
_LuaState->pop();
|
_LuaState->pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************
|
// *************************************************
|
||||||
void CLuaObject::setValue(const char *key, const char *value) throw(ELuaNotATable)
|
void CLuaObject::setValue(const char *key, const char *value) throw(ELuaNotATable)
|
||||||
{
|
{
|
||||||
nlassert(value);
|
nlassert(value);
|
||||||
nlassert(key);
|
nlassert(key);
|
||||||
nlassert(isValid());
|
nlassert(isValid());
|
||||||
|
@ -339,17 +333,17 @@ void CLuaObject::setValue(const char *key, const char *value) throw(ELuaNotATab
|
||||||
_LuaState->push(value);
|
_LuaState->push(value);
|
||||||
_LuaState->setTable(-3);
|
_LuaState->setTable(-3);
|
||||||
_LuaState->pop();
|
_LuaState->pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************
|
// *************************************************
|
||||||
void CLuaObject::setValue(const char *key, const std::string &value) throw(ELuaNotATable)
|
void CLuaObject::setValue(const char *key, const std::string &value) throw(ELuaNotATable)
|
||||||
{
|
{
|
||||||
setValue(key, value.c_str());
|
setValue(key, value.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************
|
// *************************************************
|
||||||
void CLuaObject::setValue(const char *key, bool value) throw(ELuaNotATable)
|
void CLuaObject::setValue(const char *key, bool value) throw(ELuaNotATable)
|
||||||
{
|
{
|
||||||
nlassert(key);
|
nlassert(key);
|
||||||
nlassert(isValid());
|
nlassert(isValid());
|
||||||
if (!isTable()) throw ELuaNotATable(NLMISC::toString("Trying to set a value '%s' at key %s on object '%s' of type %s (not a table).", value ? "true" : "false", key, getId().c_str(), getTypename()));
|
if (!isTable()) throw ELuaNotATable(NLMISC::toString("Trying to set a value '%s' at key %s on object '%s' of type %s (not a table).", value ? "true" : "false", key, getId().c_str(), getTypename()));
|
||||||
|
@ -359,11 +353,11 @@ void CLuaObject::setValue(const char *key, bool value) throw(ELuaNotATable)
|
||||||
_LuaState->push(value);
|
_LuaState->push(value);
|
||||||
_LuaState->setTable(-3);
|
_LuaState->setTable(-3);
|
||||||
_LuaState->pop();
|
_LuaState->pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************
|
// *************************************************
|
||||||
void CLuaObject::setValue(const char *key, TLuaWrappedFunction value) throw(ELuaNotATable)
|
void CLuaObject::setValue(const char *key, TLuaWrappedFunction value) throw(ELuaNotATable)
|
||||||
{
|
{
|
||||||
nlassert(key);
|
nlassert(key);
|
||||||
nlassert(isValid());
|
nlassert(isValid());
|
||||||
if (!isTable()) throw ELuaNotATable(NLMISC::toString("Trying to set a function value '%p' at key %s on object '%s' of type %s (not a table).", value, key, getId().c_str(), getTypename()));
|
if (!isTable()) throw ELuaNotATable(NLMISC::toString("Trying to set a function value '%p' at key %s on object '%s' of type %s (not a table).", value, key, getId().c_str(), getTypename()));
|
||||||
|
@ -373,11 +367,11 @@ void CLuaObject::setValue(const char *key, TLuaWrappedFunction value) throw(ELua
|
||||||
_LuaState->push(value);
|
_LuaState->push(value);
|
||||||
_LuaState->setTable(-3);
|
_LuaState->setTable(-3);
|
||||||
_LuaState->pop();
|
_LuaState->pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************
|
// *************************************************
|
||||||
void CLuaObject::setValue(const char *key, double value) throw(ELuaNotATable)
|
void CLuaObject::setValue(const char *key, double value) throw(ELuaNotATable)
|
||||||
{
|
{
|
||||||
nlassert(key);
|
nlassert(key);
|
||||||
nlassert(isValid());
|
nlassert(isValid());
|
||||||
if (!isTable()) throw ELuaNotATable(NLMISC::toString("Trying to set a value '%lf' at key %s on object '%s' of type %s (not a table).", value, key, getId().c_str(), getTypename()));
|
if (!isTable()) throw ELuaNotATable(NLMISC::toString("Trying to set a value '%lf' at key %s on object '%s' of type %s (not a table).", value, key, getId().c_str(), getTypename()));
|
||||||
|
@ -387,11 +381,11 @@ void CLuaObject::setValue(const char *key, double value) throw(ELuaNotATable)
|
||||||
_LuaState->push(value);
|
_LuaState->push(value);
|
||||||
_LuaState->setTable(-3);
|
_LuaState->setTable(-3);
|
||||||
_LuaState->pop();
|
_LuaState->pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************
|
// *************************************************
|
||||||
void CLuaObject::eraseValue(const char *key) throw(ELuaNotATable)
|
void CLuaObject::eraseValue(const char *key) throw(ELuaNotATable)
|
||||||
{
|
{
|
||||||
nlassert(isValid());
|
nlassert(isValid());
|
||||||
nlassert(key);
|
nlassert(key);
|
||||||
if (!isTable()) throw ELuaNotATable(NLMISC::toString("Trying to erase a value with key '%s' on object '%s' of type %s (not a table).", key, getId().c_str(), getTypename()));
|
if (!isTable()) throw ELuaNotATable(NLMISC::toString("Trying to erase a value with key '%s' on object '%s' of type %s (not a table).", key, getId().c_str(), getTypename()));
|
||||||
|
@ -401,11 +395,11 @@ void CLuaObject::eraseValue(const char *key) throw(ELuaNotATable)
|
||||||
_LuaState->pushNil();
|
_LuaState->pushNil();
|
||||||
_LuaState->setTable(-3);
|
_LuaState->setTable(-3);
|
||||||
_LuaState->pop();
|
_LuaState->pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************
|
// *************************************************
|
||||||
bool CLuaObject::callNoThrow(int numArgs, int numRet)
|
bool CLuaObject::callNoThrow(int numArgs, int numRet)
|
||||||
{
|
{
|
||||||
nlassert(isValid());
|
nlassert(isValid());
|
||||||
if (!isFunction())
|
if (!isFunction())
|
||||||
{
|
{
|
||||||
|
@ -443,11 +437,11 @@ bool CLuaObject::callNoThrow(int numArgs, int numRet)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************
|
// *************************************************
|
||||||
bool CLuaObject::callMethodByNameNoThrow(const char *name, int numArgs, int numRet)
|
bool CLuaObject::callMethodByNameNoThrow(const char *name, int numArgs, int numRet)
|
||||||
{
|
{
|
||||||
nlassert(isValid());
|
nlassert(isValid());
|
||||||
int initialStackSize = _LuaState->getTop();
|
int initialStackSize = _LuaState->getTop();
|
||||||
if (!isTable() && !isUserData())
|
if (!isTable() && !isUserData())
|
||||||
|
@ -465,15 +459,15 @@ bool CLuaObject::callMethodByNameNoThrow(const char *name, int numArgs, int numR
|
||||||
}
|
}
|
||||||
_LuaState->setTop(std::max(0, initialStackSize - numArgs));
|
_LuaState->setTop(std::max(0, initialStackSize - numArgs));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////
|
/////////////////////
|
||||||
// CLuaEnumeration //
|
// CLuaEnumeration //
|
||||||
/////////////////////
|
/////////////////////
|
||||||
|
|
||||||
// *************************************************
|
// *************************************************
|
||||||
CLuaEnumeration::CLuaEnumeration(CLuaObject &table)
|
CLuaEnumeration::CLuaEnumeration(CLuaObject &table)
|
||||||
{
|
{
|
||||||
nlassert(table.isEnumerable());
|
nlassert(table.isEnumerable());
|
||||||
CLuaState *luaState = table.getLuaState();
|
CLuaState *luaState = table.getLuaState();
|
||||||
CLuaStackChecker lsc(luaState);
|
CLuaStackChecker lsc(luaState);
|
||||||
|
@ -494,25 +488,25 @@ CLuaEnumeration::CLuaEnumeration(CLuaObject &table)
|
||||||
_Table = table;
|
_Table = table;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************
|
// *************************************************
|
||||||
const CLuaObject &CLuaEnumeration::nextKey() const
|
const CLuaObject &CLuaEnumeration::nextKey() const
|
||||||
{
|
{
|
||||||
nlassert(_HasNext);
|
nlassert(_HasNext);
|
||||||
return _Key;
|
return _Key;
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************
|
// *************************************************
|
||||||
CLuaObject &CLuaEnumeration::nextValue()
|
CLuaObject &CLuaEnumeration::nextValue()
|
||||||
{
|
{
|
||||||
nlassert(_HasNext);
|
nlassert(_HasNext);
|
||||||
return _Value;
|
return _Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************
|
// *************************************************
|
||||||
CLuaObject CLuaObject::getMetaTable() const
|
CLuaObject CLuaObject::getMetaTable() const
|
||||||
{
|
{
|
||||||
nlassert(isValid());
|
nlassert(isValid());
|
||||||
CLuaStackChecker lsc(_LuaState);
|
CLuaStackChecker lsc(_LuaState);
|
||||||
push();
|
push();
|
||||||
|
@ -524,11 +518,11 @@ CLuaObject CLuaObject::getMetaTable() const
|
||||||
_LuaState->pop();
|
_LuaState->pop();
|
||||||
_LuaState->pushNil();
|
_LuaState->pushNil();
|
||||||
return CLuaObject(*_LuaState);
|
return CLuaObject(*_LuaState);
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************
|
// *************************************************
|
||||||
bool CLuaObject::setMetaTable(CLuaObject &metatable)
|
bool CLuaObject::setMetaTable(CLuaObject &metatable)
|
||||||
{
|
{
|
||||||
nlassert(isValid());
|
nlassert(isValid());
|
||||||
nlassert(metatable.isValid());
|
nlassert(metatable.isValid());
|
||||||
nlassert(this->getLuaState() == metatable.getLuaState());
|
nlassert(this->getLuaState() == metatable.getLuaState());
|
||||||
|
@ -538,11 +532,11 @@ bool CLuaObject::setMetaTable(CLuaObject &metatable)
|
||||||
bool ok = _LuaState->setMetaTable(-2);
|
bool ok = _LuaState->setMetaTable(-2);
|
||||||
_LuaState->pop(1);
|
_LuaState->pop(1);
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************
|
// *************************************************
|
||||||
std::string CLuaObject::toStringRecurse(uint depth /*=0*/, uint maxDepth /*= 20*/, std::set<const void *> *alreadySeen /*= NULL */) const
|
std::string CLuaObject::toStringRecurse(uint depth /*=0*/, uint maxDepth /*= 20*/, std::set<const void *> *alreadySeen /*= NULL */) const
|
||||||
{
|
{
|
||||||
if (maxDepth != 0 && depth > maxDepth) return "";
|
if (maxDepth != 0 && depth > maxDepth) return "";
|
||||||
const uint INDENT_NUM_BLANK = 2;
|
const uint INDENT_NUM_BLANK = 2;
|
||||||
std::string indentStr(depth * INDENT_NUM_BLANK, ' ');
|
std::string indentStr(depth * INDENT_NUM_BLANK, ' ');
|
||||||
|
@ -600,11 +594,11 @@ std::string CLuaObject::toStringRecurse(uint depth /*=0*/, uint maxDepth /*= 20*
|
||||||
{
|
{
|
||||||
return ((indentStr + toString()).c_str());
|
return ((indentStr + toString()).c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************
|
// *************************************************
|
||||||
void CLuaObject::dump(uint maxDepth /*= 20*/, std::set<const void *> *alreadySeen /*= NULL */) const
|
void CLuaObject::dump(uint maxDepth /*= 20*/, std::set<const void *> *alreadySeen /*= NULL */) const
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
std::string str = toStringRecurse(0, maxDepth, alreadySeen);
|
std::string str = toStringRecurse(0, maxDepth, alreadySeen);
|
||||||
|
@ -620,11 +614,11 @@ void CLuaObject::dump(uint maxDepth /*= 20*/, std::set<const void *> *alreadySee
|
||||||
//CLuaIHMRyzom::dumpCallStack();
|
//CLuaIHMRyzom::dumpCallStack();
|
||||||
nlwarning(e.what());
|
nlwarning(e.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************
|
// *************************************************
|
||||||
std::string CLuaObject::concatId(const std::string &left,const std::string &right)
|
std::string CLuaObject::concatId(const std::string &left,const std::string &right)
|
||||||
{
|
{
|
||||||
if (!right.empty() && isdigit(right[0]))
|
if (!right.empty() && isdigit(right[0]))
|
||||||
{
|
{
|
||||||
if (left.empty()) return "[" + right + "]";
|
if (left.empty()) return "[" + right + "]";
|
||||||
|
@ -633,11 +627,11 @@ std::string CLuaObject::concatId(const std::string &left,const std::string &righ
|
||||||
if (left.empty()) return right;
|
if (left.empty()) return right;
|
||||||
return left + "." + right;
|
return left + "." + right;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************
|
// *************************************************
|
||||||
void CLuaEnumeration::next()
|
void CLuaEnumeration::next()
|
||||||
{
|
{
|
||||||
nlassert(_HasNext);
|
nlassert(_HasNext);
|
||||||
CLuaState *luaState = _Table.getLuaState();
|
CLuaState *luaState = _Table.getLuaState();
|
||||||
nlassert(luaState);
|
nlassert(luaState);
|
||||||
|
@ -652,5 +646,6 @@ void CLuaEnumeration::next()
|
||||||
_HasNext = !_Key.isNil();
|
_HasNext = !_Key.isNil();
|
||||||
_Value.setId(_Table.getId() + "." + _Key.toString());
|
_Value.setId(_Table.getId() + "." + _Key.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -17,31 +17,33 @@
|
||||||
|
|
||||||
#include "nel/gui/reflect.h"
|
#include "nel/gui/reflect.h"
|
||||||
|
|
||||||
// Yoyo: Act like a singleton, else registerClass may crash.
|
namespace NLGUI
|
||||||
CReflectSystem::TClassMap *CReflectSystem::_ClassMap= NULL;
|
|
||||||
|
|
||||||
// hack to register the root class at startup
|
|
||||||
static const struct CRootReflectableClassRegister
|
|
||||||
{
|
{
|
||||||
|
// Yoyo: Act like a singleton, else registerClass may crash.
|
||||||
|
CReflectSystem::TClassMap *CReflectSystem::_ClassMap= NULL;
|
||||||
|
|
||||||
|
// hack to register the root class at startup
|
||||||
|
static const struct CRootReflectableClassRegister
|
||||||
|
{
|
||||||
CRootReflectableClassRegister()
|
CRootReflectableClassRegister()
|
||||||
{
|
{
|
||||||
TReflectedProperties props;
|
TReflectedProperties props;
|
||||||
CReflectSystem::registerClass("CReflectable", "", props);
|
CReflectSystem::registerClass("CReflectable", "", props);
|
||||||
}
|
}
|
||||||
} _RootReflectableClassRegisterInstance;
|
} _RootReflectableClassRegisterInstance;
|
||||||
|
|
||||||
|
|
||||||
//===================================================================================
|
//===================================================================================
|
||||||
// release memory
|
// release memory
|
||||||
void CReflectSystem::release()
|
void CReflectSystem::release()
|
||||||
{
|
{
|
||||||
delete _ClassMap;
|
delete _ClassMap;
|
||||||
_ClassMap = NULL;
|
_ClassMap = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
//===================================================================================
|
//===================================================================================
|
||||||
void CReflectSystem::registerClass(const std::string &className, const std::string &parentName, const TReflectedProperties properties)
|
void CReflectSystem::registerClass(const std::string &className, const std::string &parentName, const TReflectedProperties properties)
|
||||||
{
|
{
|
||||||
if(!_ClassMap) _ClassMap= new TClassMap;
|
if(!_ClassMap) _ClassMap= new TClassMap;
|
||||||
|
|
||||||
TClassMap::const_iterator it = _ClassMap->find(className);
|
TClassMap::const_iterator it = _ClassMap->find(className);
|
||||||
|
@ -69,11 +71,11 @@ void CReflectSystem::registerClass(const std::string &className, const std::stri
|
||||||
}
|
}
|
||||||
ci.ParentClass = &(it->second);
|
ci.ParentClass = &(it->second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//===================================================================================
|
//===================================================================================
|
||||||
const CReflectedProperty *CReflectSystem::getProperty(const std::string &className, const std::string &propertyName, bool dspWarning)
|
const CReflectedProperty *CReflectSystem::getProperty(const std::string &className, const std::string &propertyName, bool dspWarning)
|
||||||
{
|
{
|
||||||
if(!_ClassMap) _ClassMap= new TClassMap;
|
if(!_ClassMap) _ClassMap= new TClassMap;
|
||||||
|
|
||||||
TClassMap::const_iterator it = _ClassMap->find(className);
|
TClassMap::const_iterator it = _ClassMap->find(className);
|
||||||
|
@ -104,12 +106,12 @@ const CReflectedProperty *CReflectSystem::getProperty(const std::string &classNa
|
||||||
if(dspWarning)
|
if(dspWarning)
|
||||||
nlwarning("CReflectSystem::getProperty : %s is not a property of class : %s", propertyName.c_str(), className.c_str());
|
nlwarning("CReflectSystem::getProperty : %s is not a property of class : %s", propertyName.c_str(), className.c_str());
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//===================================================================================
|
//===================================================================================
|
||||||
const CClassInfo *CReflectable::getClassInfo()
|
const CClassInfo *CReflectable::getClassInfo()
|
||||||
{
|
{
|
||||||
if (!CReflectSystem::getClassMap()) return NULL;
|
if (!CReflectSystem::getClassMap()) return NULL;
|
||||||
// TODO nico : a possible optimization would be to use the address of the static function
|
// TODO nico : a possible optimization would be to use the address of the static function
|
||||||
// 'getReflectedProperties' as a key into the CClassInfo map. This pointer uniquely identify
|
// 'getReflectedProperties' as a key into the CClassInfo map. This pointer uniquely identify
|
||||||
|
@ -120,19 +122,22 @@ const CClassInfo *CReflectable::getClassInfo()
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return &(it->second);
|
return &(it->second);
|
||||||
}
|
}
|
||||||
|
|
||||||
//===================================================================================
|
//===================================================================================
|
||||||
const CReflectedProperty *CReflectable::getReflectedProperty(const std::string &propertyName, bool dspWarning) const
|
const CReflectedProperty *CReflectable::getReflectedProperty(const std::string &propertyName, bool dspWarning) const
|
||||||
{
|
{
|
||||||
return CReflectSystem::getProperty(this->getReflectedClassName(), propertyName, dspWarning);
|
return CReflectSystem::getProperty(this->getReflectedClassName(), propertyName, dspWarning);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#include "nel/gui/lua_manager.h"
|
#include "nel/gui/lua_manager.h"
|
||||||
|
|
||||||
CReflectableRefPtrTarget::~CReflectableRefPtrTarget()
|
namespace NLGUI
|
||||||
{
|
{
|
||||||
|
CReflectableRefPtrTarget::~CReflectableRefPtrTarget()
|
||||||
|
{
|
||||||
CLuaState *lua= CLuaManager::getInstance().getLuaState();
|
CLuaState *lua= CLuaManager::getInstance().getLuaState();
|
||||||
if(!lua)
|
if(!lua)
|
||||||
return;
|
return;
|
||||||
|
@ -151,9 +156,9 @@ CReflectableRefPtrTarget::~CReflectableRefPtrTarget()
|
||||||
{
|
{
|
||||||
lua->pop();
|
lua->pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data structure pushed in lua (a userdata) to access CReflectableRefPtrTarget derived objects
|
* Data structure pushed in lua (a userdata) to access CReflectableRefPtrTarget derived objects
|
||||||
* These includes element of the GUI.
|
* These includes element of the GUI.
|
||||||
* if holds a pointer to the reflectable object, and
|
* if holds a pointer to the reflectable object, and
|
||||||
|
@ -161,18 +166,18 @@ CReflectableRefPtrTarget::~CReflectableRefPtrTarget()
|
||||||
* \see reflect.h
|
* \see reflect.h
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
inline const CClassInfo &CReflectableLuaRef::getClassInfo() const
|
inline const CClassInfo &CReflectableLuaRef::getClassInfo() const
|
||||||
{
|
{
|
||||||
nlassert(Ptr); // class info should not be accessed for a null ptr
|
nlassert(Ptr); // class info should not be accessed for a null ptr
|
||||||
if (_ClassInfo) return *_ClassInfo;
|
if (_ClassInfo) return *_ClassInfo;
|
||||||
_ClassInfo = Ptr->getClassInfo();
|
_ClassInfo = Ptr->getClassInfo();
|
||||||
return *_ClassInfo;
|
return *_ClassInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CReflectedProperty *CReflectableLuaRef::getProp(const char *luaStringPtr) const
|
const CReflectedProperty *CReflectableLuaRef::getProp(const char *luaStringPtr) const
|
||||||
{
|
{
|
||||||
const CClassInfo &ci = getClassInfo();
|
const CClassInfo &ci = getClassInfo();
|
||||||
CClassInfo::TLuaStrToPropMap::const_iterator it = ci.LuaStrToProp.find(luaStringPtr);
|
CClassInfo::TLuaStrToPropMap::const_iterator it = ci.LuaStrToProp.find(luaStringPtr);
|
||||||
if (it != ci.LuaStrToProp.end())
|
if (it != ci.LuaStrToProp.end())
|
||||||
|
@ -188,4 +193,6 @@ const CReflectedProperty *CReflectableLuaRef::getProp(const char *luaStringPtr)
|
||||||
lip.Prop = prop;
|
lip.Prop = prop;
|
||||||
ci.LuaStrToProp[luaStringPtr] = lip;
|
ci.LuaStrToProp[luaStringPtr] = lip;
|
||||||
return prop;
|
return prop;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,13 @@ namespace NLMISC
|
||||||
class CVector2f;
|
class CVector2f;
|
||||||
}
|
}
|
||||||
|
|
||||||
class CLuaObject;
|
namespace NLGUI
|
||||||
|
{
|
||||||
|
class CLuaObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
using namespace NLGUI;
|
||||||
|
|
||||||
class CDecal;
|
class CDecal;
|
||||||
|
|
||||||
// TODO nico : this would fit nicely in the particle system animation system (would be more flexible)
|
// TODO nico : this would fit nicely in the particle system animation system (would be more flexible)
|
||||||
|
|
|
@ -25,6 +25,8 @@
|
||||||
#include "interface_property.h"
|
#include "interface_property.h"
|
||||||
#include "nel/gui/reflect.h"
|
#include "nel/gui/reflect.h"
|
||||||
|
|
||||||
|
using namespace NLGUI;
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
class CInterfaceGroup;
|
class CInterfaceGroup;
|
||||||
|
|
||||||
|
|
|
@ -22,12 +22,20 @@
|
||||||
#include "nel/misc/cdb_branch.h"
|
#include "nel/misc/cdb_branch.h"
|
||||||
#include "nel/misc/cdb_branch_observing_handler.h"
|
#include "nel/misc/cdb_branch_observing_handler.h"
|
||||||
|
|
||||||
|
namespace NLGUI
|
||||||
|
{
|
||||||
|
class CReflectedProperty;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class CInterfaceElement;
|
class CInterfaceElement;
|
||||||
class CReflectedProperty;
|
|
||||||
class CInterfaceExprValue;
|
class CInterfaceExprValue;
|
||||||
class CInterfaceGroup;
|
class CInterfaceGroup;
|
||||||
class CInterfaceExprNode;
|
class CInterfaceExprNode;
|
||||||
|
|
||||||
|
using namespace NLGUI;
|
||||||
|
|
||||||
|
|
||||||
/** A link in an interface.
|
/** A link in an interface.
|
||||||
* A link is an object that can read one or several values from the database, that can evaluate an expression
|
* A link is an object that can read one or several values from the database, that can evaluate an expression
|
||||||
* on these database entries (simple computation, using the CInterfaceExpr class), and that can affect the result to
|
* on these database entries (simple computation, using the CInterfaceExpr class), and that can affect the result to
|
||||||
|
|
|
@ -3,10 +3,12 @@
|
||||||
|
|
||||||
#include "nel/gui/lua_ihm.h"
|
#include "nel/gui/lua_ihm.h"
|
||||||
|
|
||||||
|
using namespace NLGUI;
|
||||||
|
|
||||||
class CLuaIHMRyzom
|
class CLuaIHMRyzom
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static void RegisterRyzomFunctions( NLGUI::CLuaState &ls );
|
static void RegisterRyzomFunctions( CLuaState &ls );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void createLuaEnumTable(CLuaState &ls, const std::string &str);
|
static void createLuaEnumTable(CLuaState &ls, const std::string &str);
|
||||||
|
|
|
@ -21,8 +21,10 @@
|
||||||
#include "nel/misc/class_registry.h"
|
#include "nel/misc/class_registry.h"
|
||||||
#include "../interface_v3/interface_element.h"
|
#include "../interface_v3/interface_element.h"
|
||||||
|
|
||||||
class CLuaObject;
|
namespace NLGUI
|
||||||
|
{
|
||||||
|
class CLuaObject;
|
||||||
|
}
|
||||||
|
|
||||||
namespace R2
|
namespace R2
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,7 +21,12 @@
|
||||||
#include "nel/gui/lua_object.h"
|
#include "nel/gui/lua_object.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
class CLuaObject;
|
namespace NLGUI
|
||||||
|
{
|
||||||
|
class CLuaObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
using namespace NLGUI;
|
||||||
|
|
||||||
namespace R2
|
namespace R2
|
||||||
{
|
{
|
||||||
|
|
|
@ -20,8 +20,10 @@
|
||||||
namespace NLGUI
|
namespace NLGUI
|
||||||
{
|
{
|
||||||
class CLuaState;
|
class CLuaState;
|
||||||
|
class CLuaString;
|
||||||
}
|
}
|
||||||
class CLuaString;
|
|
||||||
|
using namespace NLGUI;
|
||||||
|
|
||||||
namespace R2
|
namespace R2
|
||||||
{
|
{
|
||||||
|
|
|
@ -24,8 +24,12 @@
|
||||||
#include "../interface_v3/group_map.h"
|
#include "../interface_v3/group_map.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace NLGUI
|
||||||
|
{
|
||||||
|
class CLuaObject;
|
||||||
|
}
|
||||||
|
|
||||||
class CEntityCL;
|
class CEntityCL;
|
||||||
class CLuaObject;
|
|
||||||
class CCtrlPolygon;
|
class CCtrlPolygon;
|
||||||
|
|
||||||
namespace R2
|
namespace R2
|
||||||
|
|
|
@ -29,8 +29,9 @@ class CInterfaceManager;
|
||||||
namespace NLGUI
|
namespace NLGUI
|
||||||
{
|
{
|
||||||
class CEventDescriptor;
|
class CEventDescriptor;
|
||||||
|
class CLuaObject;
|
||||||
}
|
}
|
||||||
class CLuaObject;
|
|
||||||
class CGroupMap;
|
class CGroupMap;
|
||||||
|
|
||||||
namespace NLMISC
|
namespace NLMISC
|
||||||
|
|
|
@ -25,8 +25,10 @@
|
||||||
|
|
||||||
class CEntity;
|
class CEntity;
|
||||||
class CEntityCL;
|
class CEntityCL;
|
||||||
class CLuaObject;
|
namespace NLGUI
|
||||||
|
{
|
||||||
|
class CLuaObject;
|
||||||
|
}
|
||||||
|
|
||||||
namespace R2
|
namespace R2
|
||||||
{
|
{
|
||||||
|
|
|
@ -22,8 +22,11 @@
|
||||||
#include "nel/gui/lua_object.h"
|
#include "nel/gui/lua_object.h"
|
||||||
|
|
||||||
class CEntity;
|
class CEntity;
|
||||||
class CLuaObject;
|
|
||||||
|
|
||||||
|
namespace NLGUI
|
||||||
|
{
|
||||||
|
class CLuaObject;
|
||||||
|
}
|
||||||
|
|
||||||
namespace R2
|
namespace R2
|
||||||
{
|
{
|
||||||
|
|
|
@ -25,8 +25,10 @@
|
||||||
#include "displayer_visual_entity.h"
|
#include "displayer_visual_entity.h"
|
||||||
|
|
||||||
class CEntity;
|
class CEntity;
|
||||||
class CLuaObject;
|
namespace NLGUI
|
||||||
|
{
|
||||||
|
class CLuaObject;
|
||||||
|
}
|
||||||
|
|
||||||
namespace R2
|
namespace R2
|
||||||
{
|
{
|
||||||
|
|
|
@ -25,8 +25,10 @@
|
||||||
|
|
||||||
|
|
||||||
class CEntity;
|
class CEntity;
|
||||||
class CLuaObject;
|
namespace NLGUI
|
||||||
|
{
|
||||||
|
class CLuaObject;
|
||||||
|
}
|
||||||
|
|
||||||
namespace R2
|
namespace R2
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue