From: John L. <jr...@us...> - 2005-11-25 10:09:22
|
Update of /cvsroot/wxlua/wxLua/modules/wxlua/include In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1505/wxLua/modules/wxlua/include Modified Files: internal.h wxlintrp.h wxlstate.h Log Message: flesh out the wxLuaState SmartString/IntArray to wxLuaSmartXXX TRUE/FALSE - true/false Index: wxlintrp.h =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/include/wxlintrp.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** wxlintrp.h 25 Nov 2005 02:46:53 -0000 1.1 --- wxlintrp.h 25 Nov 2005 10:09:11 -0000 1.2 *************** *** 109,113 **** void SetLuaDebugHook(int count = 1000, int yield = 50, ! bool send_debug_evt = FALSE, int hook = LUA_MASKCOUNT); int GetLuaDebugHookCount() const { return m_lua_debug_hook_count; } --- 109,113 ---- void SetLuaDebugHook(int count = 1000, int yield = 50, ! bool send_debug_evt = false, int hook = LUA_MASKCOUNT); int GetLuaDebugHookCount() const { return m_lua_debug_hook_count; } Index: wxlstate.h =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/include/wxlstate.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** wxlstate.h 25 Nov 2005 02:46:53 -0000 1.1 --- wxlstate.h 25 Nov 2005 10:09:11 -0000 1.2 *************** *** 7,10 **** --- 7,27 ---- ///////////////////////////////////////////////////////////////////////////// + /* **************************************************************************** + + Portions of code in this file have been taken from LuaPlus. + LuaPlus was written and maintained by Joshua Jensen (jj...@wo...) + and resides as http://wwhiz.com/LuaPlus/index.html . LuaPlus is distributed + with the Lua Licence as described below. + + Lua License + ----------- + Lua is licensed under the terms of the MIT license reproduced below. + This mean that Lua is free software and can be used for both academic and + commercial purposes at absolutely no cost. + + For details, see http://www.lua.org/license.html . + + **************************************************************************** */ + #ifndef _WXLSTATE_H_ #define _WXLSTATE_H_ *************** *** 29,35 **** class WXDLLIMPEXP_WXLUA wxLuaState; #include "wx/hashmap.h" ! WX_DECLARE_VOIDPTR_HASH_MAP( wxLuaState *, wxHashMapLuaState ); //---------------------------------------------------------------------------- --- 46,53 ---- class WXDLLIMPEXP_WXLUA wxLuaState; + class WXDLLIMPEXP_WXLUA wxLuaStateRefData; #include "wx/hashmap.h" ! WX_DECLARE_VOIDPTR_HASH_MAP( wxLuaStateRefData *, wxHashMapLuaStateRefData ); //---------------------------------------------------------------------------- *************** *** 44,51 **** --- 62,74 ---- virtual ~wxLuaStateRefData(); + // destroy and cleanup the lua_State, returns sucess + // if 'force' then make sure all wxWindows are destroyed. + bool Destroy(bool force); + // clear all wxLuaCallbacks on destruction void ClearCallbacks(); lua_State *m_lua_State; + bool m_lua_State_static; wxLuaBindingList m_bindings; // A list of generated lua bindings *************** *** 71,76 **** wxArrayInt m_usedIndexes; ! ! static wxHashMapLuaState s_wxHashMapLuaState; private: --- 94,99 ---- wxArrayInt m_usedIndexes; ! static wxLuaStateRefData* FindLuaStateRefData(lua_State* L); ! static wxHashMapLuaStateRefData s_wxHashMapLuaStateRefData; private: *************** *** 82,90 **** //---------------------------------------------------------------------------- class WXDLLIMPEXP_WXLUA wxLuaState : public wxObject { public: wxLuaState() : wxObject() {} ! wxLuaState( const wxLuaState& wxlState ) { Create(wxlState); } virtual ~wxLuaState() {} --- 105,122 ---- //---------------------------------------------------------------------------- + enum wxLuaState_Type + { + WXLUASTATE_CREATE = 1, // Create a new lua_State + WXLUASTATE_ATTACH = 2, // Attach to c currently created lua_State + WXLUASTATE_SETSTATE = 3 // Merely set the lua_State and don't close it + // when destroyed + }; + class WXDLLIMPEXP_WXLUA wxLuaState : public wxObject { public: wxLuaState() : wxObject() {} ! wxLuaState(lua_State* L, wxLuaState_Type type) { Create(L, type); } ! wxLuaState(const wxLuaState& wxlState) { Create(wxlState); } virtual ~wxLuaState() {} *************** *** 92,102 **** // Destroy the refed data void Destroy() { UnRef(); } // Is this wxLuaState valid, has refed data bool Ok() const { return m_refData != NULL; } ! // ----------------------------------------------------------------------- ! // (re)Create this wxLuaState, unrefing this wxLuaState first. ! void Create( const wxLuaState& wxlState ); void LUACALL RegisterBindings(bool registerTypes); --- 124,142 ---- // Destroy the refed data void Destroy() { UnRef(); } + + // Ref the given wxLuaState + void Create(const wxLuaState& wxlState); + // Create a new lua_State if L = NULL or just attach to the + // input lua_State + bool Create(lua_State* L = NULL, wxLuaState_Type type = WXLUASTATE_CREATE); + // Is this wxLuaState valid, has refed data bool Ok() const { return m_refData != NULL; } ! // Get the lua_State ! lua_State* GetLuaState() const; + // ----------------------------------------------------------------------- + // Binding functions void LUACALL RegisterBindings(bool registerTypes); *************** *** 112,123 **** --- 152,296 ---- const WXLUAEVENT * GetLuaEvent(wxEvent *pEvent); + // ----------------------------------------------------------------------- + // wxLua Lua Registry Table Functions + + // create a reference to the object at index iParam in the Lua index + int tinsert(int iParam); + // push onto the top of the stack the object referenced by iReference + bool tget(int iReference); + // remove a Lua reference + bool tremove(int iReference); + // Get the number of items in the reference table + int tgetn(); + // Display an error message + void terror(const char *errorMsg); + // push onto the top of the stack an userdata object containing u using tag to set the metatable + void tpushusertag(const void *u, int tag); + // get the tag of the object at index + int ttag(int index); + // return the user data in the userdata object at index, if reset is true clear the user data + void* ttouserdata(int index, bool reset = false); + // allocate a new metatable return its reference + int tnewtag(); + int tnewweaktag(bool fWeakKey, bool fWeakData); + // set the metatable of the object at top of stack from the reference tag + void tsettag(int tag); + // set a metamethod for the metatable referenced by tag with the supplied name and function. + // if pClass is non-null set the upvalue of the function to the supplied class + bool tsettagmethod(int tag, const char *method, lua_CFunction func, void *pClass = NULL); + + // ----------------------------------------------------------------------- + // wxLua get data type + + // Return a pointer to the object that corresponds to the specified stack + // index and tag + // get a user data type (either allocated by us if the tag is iTagS otherwise + // system allocated iTagP. if the data type does not have the correct tag, + // or if the parameter iParam is nil, NULL is returned. + // otherwise an error occurs + void* getuserdatatype(int iParam, int iTag); + // set a user data type + void pushuserdatatype(int iTag, const void *data); + + // helper functions to get numbers, booleans and strings safer + const char* getstringtype(int iParam); + bool getbooleantype(int iParam); + long getenumerationtype(int iParam); + double getnumbertype(int iParam); + + // convert a parameter which is presumably a table into a string array. + // returns the number of strings in the array in count. + // the return value may need to be deleted. + wxString* tostringarray(int iParam, int &count); + // convert a parameter which is presumably a table into a character pointer array. + // returns the number of character strings in the array in count. + // the return value may need to be deleted. + const char** tochararray(int iParam, int &count); + + // convert a parameter which is presumably a wxArrayString reference a string array. + // returns the table containing the strings on the Lua stack. + // returns the number of items in the table + int tostringtable(wxArrayString &files); + int tointtable(const wxArrayInt &table); + + // convert a parameter which is presumably a table into a integer array. + // returns the number of ints in the array in count. + // the return value may need to be deleted. + int* tointarray(int iParam, int &count); + int toarrayint(int iParam, wxArrayInt &intArray); + + // Given a lua tag, return the corresponding tag name + const char* LUACALL GetLuaTagName(int nTag); + + // get the method or 'get' property for the class at cpIndex + WXLUAMETHOD* getLuaMethod(const WXLUACLASS *pClass, const char *cpIndex, bool &isProperty); + // get the property for the class at cpIndex + WXLUAMETHOD* getLuaProperty(const WXLUACLASS *pClass, const char *cpIndex, bool isSet); + + // get the derived method for the class cpIndex + lua_State* getDerivedMethod(void *pObject, const char *method, lua_State *L = NULL); + + int LuaError(int status, int top); + int LuaCall(int narg, int clear); + int LuaDoFile(const wxString &file); + int LuaDoBuffer(const char *buffer, size_t len, const char *name); + + // Check the return value of LuaDoFile, LuaDoBuffer, lua_dostring, lua_dofile + // returns true for no error, if error fills msg with a useful message if !NULL + bool CheckRunError(int ret_val, wxString *msg); + + // ----------------------------------------------------------------------- + // Raw lua Stack functions. + // FIXME LuaStackObject Stack(int index) { return LuaStackObject(this, index); } + int GetTop(); + void SetTop(int index); + void PushValue(int index); + // FIXME void PushValue(LuaStackObject object); + void Remove(int index); + void Insert(int index); + void Replace(int index); + int CheckStack(int size); + void XMove(const wxLuaState& to, int n); + int Equal(int index1, int index2); + int RawEqual(int index1, int index2); + int LessThan(int index1, int index2); + // ----------------------------------------------------------------------- + // Raw lua Arg functions. + int TypeError(int narg, const char* tname); + int ArgError(int narg, const char* extramsg); + const char* CheckLString(int numArg, size_t* len); + const char* OptLString(int numArg, const char *def, size_t* len); + lua_Number CheckNumber(int numArg); + lua_Number OptNumber(int nArg, lua_Number def); + void ArgCheck(bool condition, int numarg, const char* extramsg); + const char* CheckString(int numArg); + const char* OptString(int numArg, const char* def); + int CheckInt(int numArg); + long CheckLong(int numArg); + int OptInt(int numArg, int def); + long OptLong(int numArg, int def); + void CheckStack(int sz, const char* msg); + void CheckType(int narg, int t); + void CheckAny(int narg); + void* CheckUData(int ud, const char* tname); + // ----------------------------------------------------------------------- + // Raw lua Debug functions. + int GetStack(int level, lua_Debug* ar); + int GetInfo(const char* what, lua_Debug* ar); + const char* GetLocal(const lua_Debug* ar, int n); + const char* SetLocal(const lua_Debug* ar, int n); + int SetHook(lua_Hook func, int mask, int count); + lua_Hook GetHook(); + unsigned long GetHookMask(); + // ----------------------------------------------------------------------- // operators + bool operator == (const wxLuaState& wxlState) const { return m_refData == wxlState.m_refData; } *************** *** 138,142 **** DECLARE_DYNAMIC_CLASS(wxLuaState) - }; --- 311,314 ---- Index: internal.h =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/include/internal.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** internal.h 25 Nov 2005 02:43:02 -0000 1.5 --- internal.h 25 Nov 2005 10:09:11 -0000 1.6 *************** *** 111,124 **** // ---------------------------------------------------------------------------- ! // SmartStringArray - A class to wrap an array of wxStrings with an ! // automatic destructor for making binding easier // ---------------------------------------------------------------------------- ! class WXDLLIMPEXP_WXLUA SmartStringArray { public: ! SmartStringArray() : m_choices(NULL) { } ! ~SmartStringArray() { if (m_choices != NULL) delete[] m_choices; } ! void operator =(wxString *choices) { m_choices = choices; } private: --- 111,124 ---- // ---------------------------------------------------------------------------- ! // wxLuaSmartStringArray - Wraps a "new" array of wxStrings with an automatic ! // destructor that "deletes" them to make binding easier // ---------------------------------------------------------------------------- ! class WXDLLIMPEXP_WXLUA wxLuaSmartStringArray { public: ! wxLuaSmartStringArray() : m_choices(NULL) { } ! ~wxLuaSmartStringArray() { if (m_choices != NULL) delete[] m_choices; } ! void operator = (wxString *choices) { m_choices = choices; } private: *************** *** 127,140 **** // ---------------------------------------------------------------------------- ! // SmartIntArray - A class to wrap an array of ints with an ! // automatic destructor for making binding easier // ---------------------------------------------------------------------------- ! class WXDLLIMPEXP_WXLUA SmartIntArray { public: ! SmartIntArray() : m_choices(NULL) { } ! ~SmartIntArray() { if (m_choices != NULL) delete[] m_choices; } ! void operator =(int *choices) { m_choices = choices; } private: --- 127,140 ---- // ---------------------------------------------------------------------------- ! // wxLuaSmartIntArray - A class to wrap a "new" array of ints with an automatic ! // destructor that "deletes" them to make binding easier. // ---------------------------------------------------------------------------- ! class WXDLLIMPEXP_WXLUA wxLuaSmartIntArray { public: ! wxLuaSmartIntArray() : m_choices(NULL) { } ! ~wxLuaSmartIntArray() { if (m_choices != NULL) delete[] m_choices; } ! void operator = (int *choices) { m_choices = choices; } private: *************** *** 244,253 **** // ---------------------------------------------------------------------------- - // Lua Registry Table Functions - int LUACALL tinsert(lua_State *L, int iParam); - bool LUACALL tremove(lua_State *L, int iIndex); - bool LUACALL tget(lua_State *L, int iIndex); - int LUACALL tgetn (lua_State *L); - // get a user data type (either allocated by us if the tag is iTagS otherwise // system allocated iTagP. if the data type does not have the correct tag, --- 244,247 ---- *************** *** 283,299 **** int LUACALL toarrayint(lua_State *L, int iParam, wxArrayInt &intArray); ! // register non-generated functions and types ! void LUACALL registerOthers(lua_State *L, bool registerTypes); ! ! // free memory associated with the lua call class. int LUACALL functionGarbageCollect(lua_State *L); ! // memory deallocation function int LUACALL garbageCollect(lua_State *L); ! // lua 'set table' tag method handler int LUACALL setTableFunc(lua_State *L); ! // lua 'get table' tag method handler int LUACALL getTableFunc(lua_State *L); ! // call a Lua function int LUACALL callFunction(lua_State *L); --- 277,290 ---- int LUACALL toarrayint(lua_State *L, int iParam, wxArrayInt &intArray); ! // free memory associated with the lua call class, lua's __gc int LUACALL functionGarbageCollect(lua_State *L); ! // memory deallocation function, lua's __gc int LUACALL garbageCollect(lua_State *L); ! // lua 'set table' tag method handler, lua's __newindex int LUACALL setTableFunc(lua_State *L); ! // lua 'get table' tag method handler, lua's __index int LUACALL getTableFunc(lua_State *L); ! // call a Lua function, lua's __call int LUACALL callFunction(lua_State *L); *************** *** 302,307 **** // global function in Lua for wiring ! int LUACALL ConnectEvent(lua_State *L); ! int LUACALL DisconnectEvent(lua_State *L); // get the method or 'get' property for the class at cpIndex --- 293,298 ---- // global function in Lua for wiring ! int LUACALL wxEvtHandler_ConnectEvent(lua_State *L); ! //int LUACALL wxEvtHandler_DisconnectEvent(lua_State *L); // get the method or 'get' property for the class at cpIndex *************** *** 318,322 **** // Check the return value of LuaDoFile, LuaDoBuffer, lua_dostring, lua_dofile ! // returns TRUE for no error, if error fills msg with a useful message if !NULL bool wxLuaCheckRunError(int ret_val, wxString *msg); --- 309,313 ---- // Check the return value of LuaDoFile, LuaDoBuffer, lua_dostring, lua_dofile ! // returns true for no error, if error fills msg with a useful message if !NULL bool wxLuaCheckRunError(int ret_val, wxString *msg); |