From: John L. <jr...@us...> - 2005-12-12 05:16:41
|
Update of /cvsroot/wxlua/wxLua/modules/wxlua/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9956/wxLua/modules/wxlua/src Modified Files: Makefile internal.cpp wxlbind.cpp wxlcallb.cpp wxlintrp.cpp wxlstate.cpp Log Message: Fix Makefiles to use wx-config --exec-prefix for lib dir remove wxLiaCheckRunError, make CheckRunError static in wxLuaState Capitalize all functions in genwxbind.lua, provide means to dump data types wxGetFreeMemory depends on wxLongLong in 2.6, rem out until solution found comment wx.rules and give better names to variables move garbageCollect, setTableFunc, getTableFunc to wxlbind.cpp from internal.cpp rename to wxLua_lua_XXX move callFunction from internal.cpp to wxlstate.cpp prepend with wxLua_lua_XXX Index: internal.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/internal.cpp,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** internal.cpp 1 Dec 2005 06:43:53 -0000 1.20 --- internal.cpp 12 Dec 2005 05:16:31 -0000 1.21 *************** *** 978,1026 **** } - // A function object needs to be deleted because the object is being - // garbage collected. - int LUACALL functionGarbageCollect(lua_State *L) - { - wxLuaState wxlState(L); - wxCHECK_MSG(wxlState.Ok(), 1, wxT("Invalid wxLuaState")); - - if (lua_isuserdata(L, 1) && (lua_islightuserdata(L, 1) == 0) && (wxlState.ttag(1) == wxlState.GetLuaFunctionTag())) - { - wxLuaFunction *pFunction = (wxLuaFunction *)wxlState.ttouserdata(1, true); - if (pFunction != NULL) - delete pFunction; - } - return 0; - } - - // if the class defines a gc function, then call it. - int LUACALL garbageCollect(lua_State *L) - { - wxLuaState wxlState(L); - wxCHECK_MSG(wxlState.Ok(), 0, wxT("Invalid wxLuaState")); - - int retVal = 0; - WXLUACLASS *pClass = (WXLUACLASS *)lua_touserdata(L, lua_upvalueindex(1)); - - if ((pClass != NULL) && lua_isuserdata(L, 1) && (lua_islightuserdata(L, 1) == 0) && (wxlState.ttag(1) == *pClass->class_tag)) - { - wxHashTable *pHashTable = (wxHashTable *) wxlState.GetLuaStateRefData()->m_pDerivedList->Delete((int)wxlState.ttouserdata(1, true)); - if (pHashTable != NULL) - delete pHashTable; - - int iMethod; - for (iMethod = 0; iMethod < pClass->num_methods; ++iMethod) - { - WXLUAMETHOD *pMethod = pClass->methods + iMethod; - if (pMethod->type == LuaDelete) - { - retVal = (*pMethod->func)(L); - break; - } - } - } - return retVal; - } - // Find a derived method given an object and and a method name. // If the method can be found, push it on to the Lua stack and return 1 --- 978,981 ---- *************** *** 1073,1219 **** } - static const char baseString[] = "base_"; - - // Called by LUA to find the method that corresponds to - // a given method name. The class to lookup is in an - // upvalue. (gettable tag method). - // If the method is a function method push the create a - // wxLua function object onto the lua stack, setting its tag - // so that the function tag of the object will be called to - // invoke the function. - // todo: Handling of properties - int LUACALL getTableFunc(lua_State *L) - { - wxLuaState wxlState(L); - wxCHECK_MSG(wxlState.Ok(), 0, wxT("Invalid wxLuaState")); - - bool fFound = false; - int result = 0; - WXLUACLASS *pClass = (WXLUACLASS *)lua_touserdata(L, lua_upvalueindex(1)); - const char *cpIndex = "{unknown}"; - - if ((pClass != NULL) && lua_isuserdata(L, 1) && - (lua_islightuserdata(L, 1) == 0) && - (wxlState.ttag(1) == *pClass->class_tag)) - { - void *pObject = wxlState.ttouserdata(1); - cpIndex = lua_tostring(L, 2); - - bool fCallbase = (memcmp(cpIndex, baseString, sizeof(baseString)-1) == 0); - if (fCallbase) - cpIndex += sizeof(baseString)-1; - else - { - if (wxlState.getDerivedMethod(pObject, cpIndex, L).Ok()) - { - fFound = true; - result = 1; - } - } - - if (!fFound) - { - bool propertyFlag; - WXLUAMETHOD *pMethod = wxlState.getLuaMethod(pClass, cpIndex, propertyFlag); - if (pMethod != NULL) - { - if (propertyFlag) - { - lua_remove(L, 2); - result = (*pMethod->func)(L); - fFound = true; - } - else - { - wxLuaFunction *pFunction = new wxLuaFunction(pMethod, pClass, pObject); - if (pFunction != NULL) - { - wxlState.tpushusertag(pFunction, wxlState.GetLuaFunctionTag()); - result = 1; - fFound = true; - } - } - } - } - } - - if (!fFound) - wxlState.terror(wx2lua(wxString::Format(_("wxLua: Attempt to call an invalid method '%s'."), lua2wx(cpIndex).c_str()))); - - return result; - } - - - // Called by LUA to find the method that corresponds to - // a given method name. The class to lookup is in an - // upvalue. (settable tag method). - // todo: Handling of properties - int LUACALL setTableFunc(lua_State *L) - { - wxLuaState wxlState(L); - wxCHECK_MSG(wxlState.Ok(), 0, wxT("Invalid wxLuaState")); - - WXLUACLASS *pClass = (WXLUACLASS *)lua_touserdata(L, lua_upvalueindex(1)); - const char *cpIndex = lua_tostring(L, 2); - - if ((pClass != NULL) && lua_isuserdata(L, 1) && - (lua_islightuserdata(L, 1) == 0) && - (wxlState.ttag(1) == *pClass->class_tag)) - { - WXLUAMETHOD *pMethod = wxlState.getLuaProperty(pClass, cpIndex, true); - if (pMethod != NULL) - { - lua_remove(L, 2); - (*pMethod->func)(L); - } - else - { - void *pObject = wxlState.ttouserdata(1); - - bool fCreated = false; - wxHashTable *pHashTable = (wxHashTable *) wxlState.GetLuaStateRefData()->m_pDerivedList->Get((int) pObject); - if (pHashTable == NULL) - { - pHashTable = new wxHashTable(wxKEY_STRING); - if (pHashTable != NULL) - { - pHashTable->DeleteContents(true); - - wxlState.GetLuaStateRefData()->m_pDerivedList->Put((int) pObject, pHashTable); - fCreated = true; - } - } - - if (pHashTable != NULL) - { - wxString index = lua2wx(cpIndex); - if (!fCreated) - { - wxLuaObject *pObject = (wxLuaObject *)pHashTable->Delete(index); - if (pObject != NULL) - delete pObject; - } - pHashTable->Put(index, new wxLuaObject(L, 3)); - } - } - } - - return 0; - } - - // Handler for the 'function' tag method. - int LUACALL callFunction(lua_State *L) - { - wxLuaState wxlState(L); - wxCHECK_MSG(wxlState.Ok(), 0, wxT("Invalid wxLuaState")); - - if (lua_isuserdata(L, 1) && (lua_islightuserdata(L, 1) == 0) && (wxlState.ttag(1) == wxlState.GetLuaFunctionTag())) - { - wxLuaFunction *pFunction = (wxLuaFunction *)wxlState.ttouserdata(1); - return pFunction->CallMethod(L); - } - return 0; - } - // Lookup and return the 'name' of a Lua object from its tag. const char * LUACALL GetLuaTagName(lua_State *L, int nTag) --- 1028,1031 ---- *************** *** 1445,1449 **** wxString errorMsg; ! if (!wxLuaCheckRunError(status, &errorMsg)) { switch(status) --- 1257,1261 ---- wxString errorMsg; ! if (!wxLuaState::CheckRunError(status, &errorMsg)) { switch(status) *************** *** 1505,1535 **** return status; } - - bool wxLuaCheckRunError(int ret_val, wxString *msg) - { - switch (ret_val) - { - case 0 : - return true; - case LUA_ERRRUN: - if (msg) *msg = wxT("wxLua: Error while running chunk"); - return false; - case LUA_ERRSYNTAX: - if (msg) *msg = wxT("wxLua: Syntax error during pre-compilation"); - return false; - case LUA_ERRMEM: - if (msg) *msg = wxT("wxLua: Memory allocation error"); - return false; - case LUA_ERRERR: - if (msg) *msg = wxT("wxLua: Generic error or an error occurred while running the error handler"); - return false; - case LUA_ERRFILE: - if (msg) *msg = wxT("wxLua: Error occurred while opening file"); - return false; - default : - if (msg) *msg = wxT("wxLua: Unknown error"); - break; - } - - return false; - } --- 1317,1318 ---- Index: Makefile =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/Makefile,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Makefile 25 Nov 2005 19:03:28 -0000 1.4 --- Makefile 12 Dec 2005 05:16:31 -0000 1.5 *************** *** 13,17 **** WXLUA_DIR = ../../.. ! WXLUA_LIBDIR = $(WXPREFIX)/lib LUA = $(WXLUA_DIR)/bin/lua --- 13,17 ---- WXLUA_DIR = ../../.. ! WXLUA_LIBDIR = $(WXLIB_DIR) LUA = $(WXLUA_DIR)/bin/lua *************** *** 21,24 **** --- 21,25 ---- WXCONFIG := wx-config WXPREFIX = $(shell $(WXCONFIG) --prefix) + WXEXECDIR = $(shell $(WXCONFIG) --exec-prefix) WXBASENAME = $(shell $(WXCONFIG) --basename) WXVERSION = $(shell $(WXCONFIG) --version) *************** *** 27,31 **** WXLDLIBS = $(shell $(WXCONFIG) --libs) WXCXX = $(shell $(WXCONFIG) --cxx) ! WXLIB_DIR = $(WXPREFIX)/lib # ---------------------------------------------------------------------------- --- 28,32 ---- WXLDLIBS = $(shell $(WXCONFIG) --libs) WXCXX = $(shell $(WXCONFIG) --cxx) ! WXLIB_DIR = $(WXEXECDIR)/lib # ---------------------------------------------------------------------------- *************** *** 34,38 **** CXX = $(WXCXX) ! APPEXTRADEFS=-I../../ -I$(WXPREFIX)/contrib/include -fexceptions -DLUACALL= TARGET_LIBNAME = lib$(WXBASENAME)_wxlua-$(WXRELEASE) --- 35,39 ---- CXX = $(WXCXX) ! APPEXTRADEFS = -I../../ -I$(WXPREFIX)/contrib/include -fexceptions -DLUACALL= TARGET_LIBNAME = lib$(WXBASENAME)_wxlua-$(WXRELEASE) Index: wxlintrp.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlintrp.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** wxlintrp.cpp 5 Dec 2005 06:11:14 -0000 1.6 --- wxlintrp.cpp 12 Dec 2005 05:16:32 -0000 1.7 *************** *** 415,419 **** // register handlers to send events ! if (inL != NULL) { RegisterFunction(LuaPrint, wxT("print")); --- 415,419 ---- // register handlers to send events ! if (inL == NULL) { RegisterFunction(LuaPrint, wxT("print")); *************** *** 589,593 **** { wxString msg; ! if (!wxLuaCheckRunError(rc, &msg)) { wxLuaEvent event(wxEVT_LUA_ERROR, GetId(), this); --- 589,593 ---- { wxString msg; ! if (!wxLuaState::CheckRunError(rc, &msg)) { wxLuaEvent event(wxEVT_LUA_ERROR, GetId(), this); Index: wxlcallb.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlcallb.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** wxlcallb.cpp 7 Dec 2005 05:53:30 -0000 1.8 --- wxlcallb.cpp 12 Dec 2005 05:16:32 -0000 1.9 *************** *** 1,4 **** ///////////////////////////////////////////////////////////////////////////// ! // Name: wxLuaCall // Purpose: A simple class for a C++ wxWidgets program to embed wxLua // Author: Francis Irving --- 1,4 ---- ///////////////////////////////////////////////////////////////////////////// ! // Name: wxLuaCallback // Purpose: A simple class for a C++ wxWidgets program to embed wxLua // Author: Francis Irving Index: wxlstate.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlstate.cpp,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** wxlstate.cpp 7 Dec 2005 05:53:30 -0000 1.12 --- wxlstate.cpp 12 Dec 2005 05:16:32 -0000 1.13 *************** *** 56,59 **** --- 56,93 ---- // ---------------------------------------------------------------------------- + // C functions for lua used in wxLuaState + // ---------------------------------------------------------------------------- + + // A function object needs to be deleted because the object is being + // garbage collected. + int LUACALL wxLua_lua_functionGarbageCollect(lua_State *L) + { + wxLuaState wxlState(L); + wxCHECK_MSG(wxlState.Ok(), 1, wxT("Invalid wxLuaState")); + + if (lua_isuserdata(L, 1) && (lua_islightuserdata(L, 1) == 0) && (wxlState.ttag(1) == wxlState.GetLuaFunctionTag())) + { + wxLuaFunction *pFunction = (wxLuaFunction *)wxlState.ttouserdata(1, true); + if (pFunction != NULL) + delete pFunction; + } + return 0; + } + + // Handler for the 'function' tag method. + int LUACALL wxLua_lua_callFunction(lua_State *L) + { + wxLuaState wxlState(L); + wxCHECK_MSG(wxlState.Ok(), 0, wxT("Invalid wxLuaState")); + + if (lua_isuserdata(L, 1) && (lua_islightuserdata(L, 1) == 0) && (wxlState.ttag(1) == wxlState.GetLuaFunctionTag())) + { + wxLuaFunction *pFunction = (wxLuaFunction *)wxlState.ttouserdata(1); + return pFunction->CallMethod(L); + } + return 0; + } + + // ---------------------------------------------------------------------------- // wxFindWindowByPointer - find a window by it's pointer // return NULL if doesn't exist, see wxFindWindowByID and wxFindWindowByLabel *************** *** 544,549 **** } ! tsettagmethod(M_WXLSTATEDATA->m_functionTag, "__gc", functionGarbageCollect); ! tsettagmethod(M_WXLSTATEDATA->m_functionTag, "__call", callFunction); } --- 578,583 ---- } ! tsettagmethod(M_WXLSTATEDATA->m_functionTag, "__gc", wxLua_lua_functionGarbageCollect); ! tsettagmethod(M_WXLSTATEDATA->m_functionTag, "__call", wxLua_lua_callFunction); } *************** *** 1064,1068 **** lua_State* L = M_WXLSTATEDATA->m_lua_State; ! if (tag != TLUA_NOTAG && tget(tag)) { if (!lua_setmetatable(L, -2)) --- 1098,1102 ---- lua_State* L = M_WXLSTATEDATA->m_lua_State; ! if ((tag != TLUA_NOTAG) && tget(tag)) { if (!lua_setmetatable(L, -2)) *************** *** 1076,1080 **** lua_State* L = M_WXLSTATEDATA->m_lua_State; ! if (tag != TLUA_NOTAG && tget(tag)) { if (pClass != NULL) --- 1110,1114 ---- lua_State* L = M_WXLSTATEDATA->m_lua_State; ! if ((tag != TLUA_NOTAG) && tget(tag)) { if (pClass != NULL) Index: wxlbind.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlbind.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** wxlbind.cpp 30 Nov 2005 04:46:17 -0000 1.7 --- wxlbind.cpp 12 Dec 2005 05:16:32 -0000 1.8 *************** *** 27,31 **** WX_DEFINE_LIST(wxLuaBindingList); ! static int LUACALL wxLuaTableErrorHandler(lua_State *L) { terror(L, "Cannot modify read-only wxLua table"); --- 27,31 ---- WX_DEFINE_LIST(wxLuaBindingList); ! static int LUACALL wxLua_lua_tableErrorHandler(lua_State *L) { terror(L, "Cannot modify read-only wxLua table"); *************** *** 33,36 **** --- 33,196 ---- } + // if the class defines a gc function, then call it. + int LUACALL wxLua_lua_garbageCollect(lua_State *L) + { + wxLuaState wxlState(L); + wxCHECK_MSG(wxlState.Ok(), 0, wxT("Invalid wxLuaState")); + + int retVal = 0; + WXLUACLASS *pClass = (WXLUACLASS *)lua_touserdata(L, lua_upvalueindex(1)); + + if ((pClass != NULL) && lua_isuserdata(L, 1) && (lua_islightuserdata(L, 1) == 0) && (wxlState.ttag(1) == *pClass->class_tag)) + { + wxHashTable *pHashTable = (wxHashTable *) wxlState.GetLuaStateRefData()->m_pDerivedList->Delete((int)wxlState.ttouserdata(1, true)); + if (pHashTable != NULL) + delete pHashTable; + + int iMethod; + for (iMethod = 0; iMethod < pClass->num_methods; ++iMethod) + { + WXLUAMETHOD *pMethod = pClass->methods + iMethod; + if (pMethod->type == LuaDelete) + { + retVal = (*pMethod->func)(L); + break; + } + } + } + return retVal; + } + + static const char baseString[] = "base_"; + + // Called by LUA to find the method that corresponds to + // a given method name. The class to lookup is in an + // upvalue. (gettable tag method). + // If the method is a function method push the create a + // wxLua function object onto the lua stack, setting its tag + // so that the function tag of the object will be called to + // invoke the function. + // todo: Handling of properties + int LUACALL wxLua_lua_getTableFunc(lua_State *L) + { + wxLuaState wxlState(L); + wxCHECK_MSG(wxlState.Ok(), 0, wxT("Invalid wxLuaState")); + + bool fFound = false; + int result = 0; + WXLUACLASS *pClass = (WXLUACLASS *)lua_touserdata(L, lua_upvalueindex(1)); + const char *cpIndex = "{unknown}"; + + if ((pClass != NULL) && lua_isuserdata(L, 1) && + (lua_islightuserdata(L, 1) == 0) && + (wxlState.ttag(1) == *pClass->class_tag)) + { + void *pObject = wxlState.ttouserdata(1); + cpIndex = lua_tostring(L, 2); + + bool fCallbase = (memcmp(cpIndex, baseString, sizeof(baseString)-1) == 0); + if (fCallbase) + cpIndex += sizeof(baseString)-1; + else + { + if (wxlState.getDerivedMethod(pObject, cpIndex, L).Ok()) + { + fFound = true; + result = 1; + } + } + + if (!fFound) + { + bool propertyFlag; + WXLUAMETHOD *pMethod = wxlState.getLuaMethod(pClass, cpIndex, propertyFlag); + if (pMethod != NULL) + { + if (propertyFlag) + { + lua_remove(L, 2); + result = (*pMethod->func)(L); + fFound = true; + } + else + { + wxLuaFunction *pFunction = new wxLuaFunction(pMethod, pClass, pObject); + if (pFunction != NULL) + { + wxlState.tpushusertag(pFunction, wxlState.GetLuaFunctionTag()); + result = 1; + fFound = true; + } + } + } + } + } + + if (!fFound) + wxlState.terror(wx2lua(wxString::Format(_("wxLua: Attempt to call an invalid method '%s'."), lua2wx(cpIndex).c_str()))); + + return result; + } + + + // Called by LUA to find the method that corresponds to + // a given method name. The class to lookup is in an + // upvalue. (settable tag method). + // todo: Handling of properties + int LUACALL wxLua_lua_setTableFunc(lua_State *L) + { + wxLuaState wxlState(L); + wxCHECK_MSG(wxlState.Ok(), 0, wxT("Invalid wxLuaState")); + + WXLUACLASS *pClass = (WXLUACLASS *)lua_touserdata(L, lua_upvalueindex(1)); + const char *cpIndex = lua_tostring(L, 2); + + if ((pClass != NULL) && lua_isuserdata(L, 1) && + (lua_islightuserdata(L, 1) == 0) && + (wxlState.ttag(1) == *pClass->class_tag)) + { + WXLUAMETHOD *pMethod = wxlState.getLuaProperty(pClass, cpIndex, true); + if (pMethod != NULL) + { + lua_remove(L, 2); + (*pMethod->func)(L); + } + else + { + void *pObject = wxlState.ttouserdata(1); + + bool fCreated = false; + wxHashTable *pHashTable = (wxHashTable *) wxlState.GetLuaStateRefData()->m_pDerivedList->Get((int) pObject); + if (pHashTable == NULL) + { + pHashTable = new wxHashTable(wxKEY_STRING); + if (pHashTable != NULL) + { + pHashTable->DeleteContents(true); + + wxlState.GetLuaStateRefData()->m_pDerivedList->Put((int) pObject, pHashTable); + fCreated = true; + } + } + + if (pHashTable != NULL) + { + wxString index = lua2wx(cpIndex); + if (!fCreated) + { + wxLuaObject *pObject = (wxLuaObject *)pHashTable->Delete(index); + if (pObject != NULL) + delete pObject; + } + pHashTable->Put(index, new wxLuaObject(L, 3)); + } + } + } + + return 0; + } + + // ---------------------------------------------------------------------------- + // Function to compare to events by eventType int wxLuaEventListCompareFn(const void *p1, const void *p2) *************** *** 116,120 **** // prevent changes from lua scripts ! wxlState.tsettagmethod(m_wxLuaTable, "__newindex", wxLuaTableErrorHandler); // register all out classes etc. in the wxLua table --- 276,280 ---- // prevent changes from lua scripts ! //wxlState.tsettagmethod(m_wxLuaTable, "__newindex", wxLua_lua_tableErrorHandler); // FIXME allow this? // register all out classes etc. in the wxLua table *************** *** 132,138 **** static const luaL_reg funcTable[] = { ! {"__gc", garbageCollect }, ! {"__index", getTableFunc }, ! {"__newindex", setTableFunc } }; static const unsigned funcCount = sizeof(funcTable)/sizeof(funcTable[0]); --- 292,298 ---- static const luaL_reg funcTable[] = { ! {"__gc", wxLua_lua_garbageCollect }, ! {"__index", wxLua_lua_getTableFunc }, ! {"__newindex", wxLua_lua_setTableFunc } }; static const unsigned funcCount = sizeof(funcTable)/sizeof(funcTable[0]); *************** *** 141,152 **** lua_State *L = wxlState.GetLuaState(); - size_t iClass; if (registerTypes) m_startTag = wxlState.tnewtag(); int iTag = m_startTag; // install the classes, functions and methods m_classList = (*pfGetClassList)(m_classCount); for (iClass = 0; iClass < m_classCount; ++iClass, iTag = registerTypes ? wxlState.tnewtag() : iTag + 1) --- 301,313 ---- lua_State *L = wxlState.GetLuaState(); if (registerTypes) m_startTag = wxlState.tnewtag(); + size_t iClass = 0; int iTag = m_startTag; // install the classes, functions and methods m_classList = (*pfGetClassList)(m_classCount); + for (iClass = 0; iClass < m_classCount; ++iClass, iTag = registerTypes ? wxlState.tnewtag() : iTag + 1) |