From: John L. <jr...@us...> - 2007-12-13 00:47:59
|
Update of /cvsroot/wxlua/wxLua/modules/wxlua/src In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv15370/wxLua/modules/wxlua/src Modified Files: wxlbind.cpp wxlcallb.cpp wxlstate.cpp wxlua.cpp wxlua_bind.cpp Log Message: * Allowed using wxObject:DynamicCast() on an object and be able to use the object as both types. The problem was that wxEvent:GetEventObject() returned a wxObject which overwrote the wxWindow (perhaps) that you had as a userdata in Lua already. Additionally, if you delete an object all of the userdata that wrap it have their metatables cleared for safety. Functions renamed since they didn't do the same thing or behave the same. wxluaO_istrackedobject -> wxluaO_isgcobject wxluaO_addtrackedobject -> wxluaO_addgcobject wxluaO_removetrackedobject -> wxluaO_deletegcobject - Created a central luauserdata:delete() function for the bindings to reduce code. wxLua_wxluabind_delete(L) wxLuaStackDialog: You can expand both key and values of a table and more information is provided about items wxLua knows about. Index: wxlua.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlua.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** wxlua.cpp 10 Dec 2007 05:39:10 -0000 1.7 --- wxlua.cpp 13 Dec 2007 00:47:52 -0000 1.8 *************** *** 34,50 **** static wxLuaArgTag s_wxluatagArray_wxLua_wxLuaState_delete[] = { &s_wxluatag_wxLuaState, NULL }; ! static int LUACALL wxLua_wxLuaState_delete(lua_State *L); ! static wxLuaBindCFunc s_wxluafunc_wxLua_wxLuaState_delete[1] = {{ wxLua_wxLuaState_delete, WXLUAMETHOD_METHOD|WXLUAMETHOD_DELETE, 1, 1, s_wxluatagArray_wxLua_wxLuaState_delete }}; ! static int LUACALL wxLua_wxLuaState_delete(lua_State *L) ! { ! wxLuaState * self = (wxLuaState *)wxluaT_getuserdatatype(L, 1, s_wxluatag_wxLuaState); ! // if removed from tracked mem list, reset the tag so that gc() is not called on this object. ! if ((self != NULL) && wxluaO_removetrackedobject(L, self, wxLUA_DELETE_CLEAR_OBJECT)) ! { ! lua_pushnil(L); ! lua_setmetatable(L, -2); ! } ! return 0; ! } --- 34,38 ---- static wxLuaArgTag s_wxluatagArray_wxLua_wxLuaState_delete[] = { &s_wxluatag_wxLuaState, NULL }; ! static wxLuaBindCFunc s_wxluafunc_wxLua_wxLuaState_delete[1] = {{ wxLua_wxluabind_delete, WXLUAMETHOD_METHOD|WXLUAMETHOD_DELETE, 1, 1, s_wxluatagArray_wxLua_wxLuaState_delete }}; *************** *** 116,132 **** static wxLuaArgTag s_wxluatagArray_wxLua_wxLuaObject_delete[] = { &s_wxluatag_wxLuaObject, NULL }; ! static int LUACALL wxLua_wxLuaObject_delete(lua_State *L); ! static wxLuaBindCFunc s_wxluafunc_wxLua_wxLuaObject_delete[1] = {{ wxLua_wxLuaObject_delete, WXLUAMETHOD_METHOD|WXLUAMETHOD_DELETE, 1, 1, s_wxluatagArray_wxLua_wxLuaObject_delete }}; ! static int LUACALL wxLua_wxLuaObject_delete(lua_State *L) ! { ! wxLuaObject * self = (wxLuaObject *)wxluaT_getuserdatatype(L, 1, s_wxluatag_wxLuaObject); ! // if removed from tracked mem list, reset the tag so that gc() is not called on this object. ! if ((self != NULL) && wxluaO_removetrackedobject(L, self, wxLUA_DELETE_CLEAR_OBJECT)) ! { ! lua_pushnil(L); ! lua_setmetatable(L, -2); ! } ! return 0; ! } static int LUACALL wxLua_wxLuaObject_constructor(lua_State *L); --- 104,108 ---- static wxLuaArgTag s_wxluatagArray_wxLua_wxLuaObject_delete[] = { &s_wxluatag_wxLuaObject, NULL }; ! static wxLuaBindCFunc s_wxluafunc_wxLua_wxLuaObject_delete[1] = {{ wxLua_wxluabind_delete, WXLUAMETHOD_METHOD|WXLUAMETHOD_DELETE, 1, 1, s_wxluatagArray_wxLua_wxLuaObject_delete }}; static int LUACALL wxLua_wxLuaObject_constructor(lua_State *L); *************** *** 143,147 **** returns = new wxLuaObject(wxlState, 1); // add to tracked memory list ! wxluaO_addtrackedobject(L, returns); // push the constructed class pointer wxluaT_pushuserdatatype(L, s_wxluatag_wxLuaObject, returns); --- 119,123 ---- returns = new wxLuaObject(wxlState, 1); // add to tracked memory list ! wxluaO_addgcobject(L, returns); // push the constructed class pointer wxluaT_pushuserdatatype(L, s_wxluatag_wxLuaObject, returns); Index: wxlstate.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlstate.cpp,v retrieving revision 1.149 retrieving revision 1.150 diff -C2 -d -r1.149 -r1.150 *** wxlstate.cpp 10 Dec 2007 05:39:10 -0000 1.149 --- wxlstate.cpp 13 Dec 2007 00:47:51 -0000 1.150 *************** *** 23,26 **** --- 23,28 ---- #include "wx/tokenzr.h" + //#include "wxluadebug/include/wxldebug.h" // for debugging only + const char* wxlua_lreg_tags_key = "wxLua metatable class tags"; const char* wxlua_lreg_refs_key = "wxLua object references"; *************** *** 30,34 **** const char* wxlua_lreg_wxluastate_key = "wxLuaState"; const char* wxlua_lreg_weakobjects_key = "wxLua objects pushed"; ! const char* wxlua_lreg_delobjects_key = "wxLua objects to delete"; const char* wxlua_lreg_evtcallbacks_key = "wxLuaCallbacks"; const char* wxlua_lreg_windestroycallbacks_key = "wxLuaWinDestoyCallbacks"; --- 32,36 ---- const char* wxlua_lreg_wxluastate_key = "wxLuaState"; const char* wxlua_lreg_weakobjects_key = "wxLua objects pushed"; ! const char* wxlua_lreg_gcobjects_key = "wxLua gc objects to delete"; const char* wxlua_lreg_evtcallbacks_key = "wxLuaCallbacks"; const char* wxlua_lreg_windestroycallbacks_key = "wxLuaWinDestoyCallbacks"; *************** *** 503,507 **** } ! bool LUACALL wxluaT_pushusertag(lua_State *L, const void *u, int tag, bool track) { // First check to see if we've already pushed this object into Lua. --- 505,509 ---- } ! bool LUACALL wxluaT_pushusertag(lua_State *L, const void *obj_ptr, int tag, bool track) { // First check to see if we've already pushed this object into Lua. *************** *** 514,530 **** if (tag != g_wxluatag_wxLuaFunction) { ! lua_pushlightuserdata(L, &wxlua_lreg_weakobjects_key); // push key ! lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push value (the obj table) ! ! lua_pushlightuserdata(L, (void*)u); // push key ! lua_rawget(L, -2); // get t[key] value; pop key push value ! ! if (wxlua_iswxuserdata(L, -1)) ! { ! lua_remove(L, -2); // remove the obj table, leave value on the stack return true; - } - - lua_pop(L, 2); // pop the table and the nil. } --- 516,521 ---- if (tag != g_wxluatag_wxLuaFunction) { ! if (wxluaO_istrackedweakobject(L, (void*)obj_ptr, tag, true)) return true; } *************** *** 533,537 **** if (ptr != NULL) { ! *ptr = u; // try to get the object's references table and set the metatable to the object if (wxluaR_getref(L, tag, &wxlua_lreg_tags_key)) --- 524,528 ---- if (ptr != NULL) { ! *ptr = obj_ptr; // try to get the object's references table and set the metatable to the object if (wxluaR_getref(L, tag, &wxlua_lreg_tags_key)) *************** *** 541,554 **** { if (track) ! { ! lua_pushlightuserdata(L, &wxlua_lreg_weakobjects_key); // push key ! lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push value (the obj table) ! ! lua_pushlightuserdata(L, (void*)u); // key on the object since we can reuse the userdata ! lua_pushvalue(L, -3); // push the Lua userdata as the value (note: weak valued table) ! ! lua_rawset(L, -3); // t[key] = value; pops key and value ! lua_pop(L, 1); // pop obj table ! } return true; // leave value on the stack --- 532,536 ---- { if (track) ! wxluaO_trackweakobject(L, -1, (void*)obj_ptr, tag); return true; // leave value on the stack *************** *** 619,630 **** // ---------------------------------------------------------------------------- ! void LUACALL wxluaO_addtrackedobject(lua_State *L, wxObject* wxobj) { ! wxluaO_addtrackedobject(L, (void*)wxobj, wxobj); } ! void LUACALL wxluaO_addtrackedobject(lua_State *L, const void *obj_ptr, wxObject* wxobj) { ! lua_pushlightuserdata(L, &wxlua_lreg_delobjects_key); // push key ! lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push value (table) // Check if it's already tracked since there's a serious problem if it is --- 601,612 ---- // ---------------------------------------------------------------------------- ! void LUACALL wxluaO_addgcobject(lua_State *L, wxObject* wxobj) { ! wxluaO_addgcobject(L, (void*)wxobj, wxobj); } ! void LUACALL wxluaO_addgcobject(lua_State *L, const void *obj_ptr, wxObject* wxobj) { ! lua_pushlightuserdata(L, &wxlua_lreg_gcobjects_key); // push key ! lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push value (table) // Check if it's already tracked since there's a serious problem if it is *************** *** 634,638 **** { lua_pop(L, 2); // pop table and value ! wxFAIL_MSG(wxT("Tracking an object the second time in wxluaO_addtrackedobject")); return; } --- 616,620 ---- { lua_pop(L, 2); // pop table and value ! wxFAIL_MSG(wxT("Tracking an object twice in wxluaO_addgcobject: ") + wxString(wxobj->GetClassInfo()->GetClassName())); return; } *************** *** 647,703 **** } ! bool LUACALL wxluaO_removetrackedobject(lua_State *L, void *obj_ptr, int flags) { ! // No derived methods anymore ! if (WXLUA_HASBIT(flags, wxLUA_CLEAR_DERIVED_METHODS)) ! wxlua_removederivedmethod(L, obj_ptr); ! // Nor are we tracking it as a weak object ! if (WXLUA_HASBIT(flags, wxLUA_CLEAR_TRACKED_OBJECT)) { ! lua_pushlightuserdata(L, &wxlua_lreg_weakobjects_key); // push key ! lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push value (the object table) ! ! lua_pushlightuserdata(L, (void*)obj_ptr); // push key ! lua_pushnil(L); // push value ! lua_rawset(L, -3); // set t[key] = nil; pops key and value ! lua_pop(L, 1); // pop objects table } ! lua_pushlightuserdata(L, &wxlua_lreg_delobjects_key); // push key ! lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push value (table) ! lua_pushlightuserdata(L, obj_ptr); // push key ! lua_rawget(L, -2); // get t[key] = value, pops key ! if (lua_islightuserdata(L, -1)) ! { ! // delete the real object for the case where it's encapsulated ! if (WXLUA_HASBIT(flags, wxLUA_DELETE_OBJECT)) { ! wxObject *del_obj = (wxObject*)lua_touserdata(L, -1); ! delete del_obj; ! } ! lua_pop(L, 1); // pop lightuserdata ! lua_pushlightuserdata(L, obj_ptr); // push key ! lua_pushnil(L); // push value ! lua_rawset(L, -3); // set t[key] = value, pops key and value ! lua_pop(L, 1); // pop delobj table ! return true; } - else - lua_pop(L, 2); // pop nil and delobj return false; } ! bool LUACALL wxluaO_istrackedobject(lua_State *L, void *obj_ptr) { ! lua_pushlightuserdata(L, &wxlua_lreg_delobjects_key); // push key ! lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push value (table) lua_pushlightuserdata(L, obj_ptr); // push key --- 629,685 ---- } ! bool LUACALL wxluaO_deletegcobject(lua_State *L, void *obj_ptr, int flags) { ! if (obj_ptr == 0) return false; ! // No derived methods and remove weak refs to it ! if (WXLUA_HASBIT(flags, wxLUA_REMOVE_OBJECT)) { ! wxlua_removederivedmethod(L, obj_ptr); ! wxluaO_untrackweakobject(L, obj_ptr); } ! if (WXLUA_HASBIT(flags, wxLUA_UNDELETE_OBJECT|wxLUA_DELETE_OBJECT)) ! { ! lua_pushlightuserdata(L, &wxlua_lreg_gcobjects_key); // push key ! lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push value (table) ! lua_pushlightuserdata(L, obj_ptr); // push key ! lua_rawget(L, -2); // get t[key] = value, pops key ! if (lua_islightuserdata(L, -1)) // is the wxObject* we delete { ! // delete the real object for the case where it's encapsulated ! if (WXLUA_HASBIT(flags, wxLUA_DELETE_OBJECT)) ! { ! wxObject *wxobj_ptr = (wxObject*)lua_touserdata(L, -1); ! delete wxobj_ptr; ! } ! lua_pop(L, 1); // pop lightuserdata ! lua_pushlightuserdata(L, obj_ptr); // push key ! lua_pushnil(L); // push value ! lua_rawset(L, -3); // set t[key] = value, pops key and value ! lua_pop(L, 1); // pop delobj table ! return true; ! } ! else ! { ! // no error message since we're called from wxluabind__gc_wxLuaBindClass ! // automatically for all our objects and this table stores which ones to delete ! lua_pop(L, 2); // pop nil and delobj ! } } return false; } ! bool LUACALL wxluaO_isgcobject(lua_State *L, void *obj_ptr) { ! lua_pushlightuserdata(L, &wxlua_lreg_gcobjects_key); // push key ! lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push value (table) lua_pushlightuserdata(L, obj_ptr); // push key *************** *** 710,719 **** } ! wxArrayString LUACALL wxluaO_gettrackedobjectstrings(lua_State *L) { wxArrayString arrStr; ! lua_pushlightuserdata(L, &wxlua_lreg_delobjects_key); // push key ! lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push value (table) lua_pushnil(L); --- 692,701 ---- } ! wxArrayString LUACALL wxluaO_getgcobjectstrings(lua_State *L) { wxArrayString arrStr; ! lua_pushlightuserdata(L, &wxlua_lreg_gcobjects_key); // push key ! lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push value (table) lua_pushnil(L); *************** *** 738,756 **** } ! void LUACALL wxluaO_cleartrackedmetatable(lua_State *L, const void *u) { lua_pushlightuserdata(L, &wxlua_lreg_weakobjects_key); // push key lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push value (the object table) ! lua_pushlightuserdata(L, (void*)u); // push key ! lua_rawget(L, -2); // get t[key] = value; pop key push value ! if (lua_isuserdata(L, -1)) { lua_pushnil(L); ! lua_setmetatable(L, -2); // set nil to metatable } ! lua_pop(L, 2); // pop object table and [userdata or nil] } --- 720,826 ---- } ! void LUACALL wxluaO_trackweakobject(lua_State *L, int udata_stack_idx, void *obj_ptr, int tag) ! { ! lua_pushlightuserdata(L, &wxlua_lreg_weakobjects_key); // push key ! lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push value (the obj table) ! ! lua_pushlightuserdata(L, obj_ptr); // key on the object since we can reuse the userdata ! lua_rawget(L, -2); ! ! if (lua_isnil(L, -1)) ! { ! lua_pop(L, 1); // pop nil ! ! lua_pushlightuserdata(L, obj_ptr); ! lua_newtable(L); ! lua_newtable(L); // metatable ! lua_pushlstring(L, "__mode", 6); ! lua_pushlstring(L, "v", 1); ! lua_rawset(L, -3); // set mode of main table ! lua_setmetatable(L, -2); // via the metatable ! lua_rawset(L, -3); ! ! lua_pushlightuserdata(L, obj_ptr); // get the table back ! lua_rawget(L, -2); ! } ! else ! { ! lua_pushnumber(L, tag); // check for dupes since that's what we're trying to avoid ! lua_rawget(L, -2); ! // this must never happen ! if (!lua_isnil(L, -1)) wxFAIL_MSG(wxT("Trying to push userdata for object with same tag twice")); ! lua_pop(L, 1); // pop nil ! } ! ! lua_pushnumber(L, tag); ! lua_pushvalue(L, ABS_LUA_STKIDX(udata_stack_idx, 3)); // push the Lua userdata as the value (note: weak valued table) ! lua_rawset(L, -3); // t[key] = value; pops key and value ! lua_pop(L, 2); // pop weakobj table and obj table ! } ! ! bool LUACALL wxluaO_untrackweakobject(lua_State *L, void *obj_ptr) { lua_pushlightuserdata(L, &wxlua_lreg_weakobjects_key); // push key lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push value (the object table) ! lua_pushlightuserdata(L, (void*)obj_ptr); // push key ! lua_rawget(L, -2); // get t[key] = value; pop key push value ! if (lua_istable(L, -1)) { + // clear the metatables for all the userdata since the object is gone! lua_pushnil(L); ! while (lua_next(L, -2) != 0) ! { ! // value = -1, key = -2, table = -3 ! lua_pushnil(L); ! lua_setmetatable(L, -2); // remove value's metatable ! lua_pop(L, 1); // pop value, leave key for next iteration ! } ! ! lua_pop(L, 1); // pop obj_ptr table ! ! lua_pushlightuserdata(L, (void*)obj_ptr); // push key ! lua_pushnil(L); // push value ! lua_rawset(L, -3); // set t[key] = nil; pops key and value ! lua_pop(L, 1); // pop objects table ! return true; } + else + lua_pop(L, 2); // pop nil and weakobj table ! return false; ! } ! ! bool LUACALL wxluaO_istrackedweakobject(lua_State *L, void *obj_ptr, int tag, bool push_on_stack) ! { ! lua_pushlightuserdata(L, &wxlua_lreg_weakobjects_key); // push key ! lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push value (the obj table) ! ! lua_pushlightuserdata(L, obj_ptr); // push key ! lua_rawget(L, -2); // get t[key] value; pop key push value ! ! if (lua_istable(L, -1)) ! { ! lua_pushnumber(L, tag); // push key ! lua_rawget(L, -2); // get t[key] = value; pops key ! ! // check if they've dynamic casted the object or if it was casted in C++ ! if (wxlua_iswxuserdata(L, -1) && (tag == wxluaT_gettag(L, -1))) ! { ! if (push_on_stack) ! { ! lua_remove(L, -3); // remove the obj table, leave value on the stack ! lua_remove(L, -2); // remove table of userdata, leave value on the stack ! } ! else ! lua_pop(L, 3); ! ! return true; ! } ! } ! ! lua_pop(L, 2); // pop the table and the nil. ! return false; } *************** *** 1861,1865 **** // Delete all the wxObject data ! lua_pushlightuserdata(m_lua_State, &wxlua_lreg_delobjects_key); lua_rawget(m_lua_State, LUA_REGISTRYINDEX); --- 1931,1935 ---- // Delete all the wxObject data ! lua_pushlightuserdata(m_lua_State, &wxlua_lreg_gcobjects_key); lua_rawget(m_lua_State, LUA_REGISTRYINDEX); *************** *** 1877,1881 **** // remove table since we've deleted everything in it ! lua_pushlightuserdata(m_lua_State, &wxlua_lreg_delobjects_key); lua_newtable(m_lua_State); lua_rawset(m_lua_State, LUA_REGISTRYINDEX); --- 1947,1951 ---- // remove table since we've deleted everything in it ! lua_pushlightuserdata(m_lua_State, &wxlua_lreg_gcobjects_key); lua_newtable(m_lua_State); lua_rawset(m_lua_State, LUA_REGISTRYINDEX); *************** *** 2084,2098 **** // Use weak values so the gc works on them wxlua_lreg_createtable(L, &wxlua_lreg_weakobjects_key); - lua_pushlightuserdata(L, &wxlua_lreg_weakobjects_key); - lua_rawget(L, LUA_REGISTRYINDEX); - lua_newtable(L); // metatable - lua_pushlstring(L, "__mode", 6); - lua_pushlstring(L, "v", 1); - lua_rawset(L, -3); // set mode of main table - lua_setmetatable(L, -2); // via the metatable - lua_pop(L, 1); // Create a table for objects to delete ! wxlua_lreg_createtable(L, &wxlua_lreg_delobjects_key); // Create a table for wxLuaCallbacks --- 2154,2160 ---- // Use weak values so the gc works on them wxlua_lreg_createtable(L, &wxlua_lreg_weakobjects_key); // Create a table for objects to delete ! wxlua_lreg_createtable(L, &wxlua_lreg_gcobjects_key); // Create a table for wxLuaCallbacks *************** *** 2683,2713 **** // memory tracking functions ! void wxLuaState::AddTrackedObject(wxObject *pObject) { ! AddTrackedObject(pObject, pObject); } ! void wxLuaState::AddTrackedObject(const void* obj_ptr, wxObject *pObject) { wxCHECK_RET(Ok() && pObject, wxT("Invalid wxLuaState or wxObject to track")); ! wxluaO_addtrackedobject(M_WXLSTATEDATA->m_lua_State, obj_ptr, pObject); } ! bool wxLuaState::RemoveTrackedObject(void *obj_ptr, int flags) { wxCHECK_MSG(Ok() && obj_ptr, false, wxT("Invalid wxLuaState or object")); ! return wxluaO_removetrackedobject(M_WXLSTATEDATA->m_lua_State, obj_ptr, flags); } ! bool wxLuaState::IsTrackedObject(void *obj_ptr) const { wxCHECK_MSG(Ok(), false, wxT("Invalid wxLuaState")); ! return wxluaO_istrackedobject(M_WXLSTATEDATA->m_lua_State, obj_ptr); } ! wxArrayString wxLuaState::GetTrackedObjectStrings() { wxCHECK_MSG(Ok(), wxArrayString(), wxT("Invalid wxLuaState")); ! return wxluaO_gettrackedobjectstrings(M_WXLSTATEDATA->m_lua_State); } --- 2745,2775 ---- // memory tracking functions ! void wxLuaState::AddGCObject(wxObject *pObject) { ! AddGCObject(pObject, pObject); } ! void wxLuaState::AddGCObject(const void* obj_ptr, wxObject *pObject) { wxCHECK_RET(Ok() && pObject, wxT("Invalid wxLuaState or wxObject to track")); ! wxluaO_addgcobject(M_WXLSTATEDATA->m_lua_State, obj_ptr, pObject); } ! bool wxLuaState::DeleteGCObject(void *obj_ptr, int flags) { wxCHECK_MSG(Ok() && obj_ptr, false, wxT("Invalid wxLuaState or object")); ! return wxluaO_deletegcobject(M_WXLSTATEDATA->m_lua_State, obj_ptr, flags); } ! bool wxLuaState::IsGCObject(void *obj_ptr) const { wxCHECK_MSG(Ok(), false, wxT("Invalid wxLuaState")); ! return wxluaO_isgcobject(M_WXLSTATEDATA->m_lua_State, obj_ptr); } ! wxArrayString wxLuaState::GetGCObjectStrings() { wxCHECK_MSG(Ok(), wxArrayString(), wxT("Invalid wxLuaState")); ! return wxluaO_getgcobjectstrings(M_WXLSTATEDATA->m_lua_State); } Index: wxlbind.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlbind.cpp,v retrieving revision 1.103 retrieving revision 1.104 diff -C2 -d -r1.103 -r1.104 *** wxlbind.cpp 10 Dec 2007 05:39:10 -0000 1.103 --- wxlbind.cpp 13 Dec 2007 00:47:51 -0000 1.104 *************** *** 20,24 **** #include "wxlua/include/wxlstate.h" ! #include "wxluadebug/include/wxldebug.h" // for debugging only #include "wx/listimpl.cpp" --- 20,24 ---- #include "wxlua/include/wxlstate.h" ! //#include "wxluadebug/include/wxldebug.h" // for debugging only #include "wx/listimpl.cpp" *************** *** 564,567 **** --- 564,590 ---- // ---------------------------------------------------------------------------- + // Generic delete function for bindings + // ---------------------------------------------------------------------------- + + int LUACALL wxLua_wxluabind_delete(lua_State *L) + { + void* self = wxlua_touserdata(L, 1, false); + // if removed from tracked mem list, reset the tag so that gc() is not called on this object. + if ((self != NULL) && wxluaO_deletegcobject(L, self, wxLUA_DELETE_REMOVE_OBJECT)) + { + lua_pushnil(L); + lua_setmetatable(L, -2); + } + else + { + // leave this printf since we really want to know if this happens + wxPrintf(wxT("Unable to call wxuserdata:delete() on object %p\n"), self); + wxlua_error(L, wxString::Format(wxT("Unable to call wxuserdata:delete() on object %p"), self)); + } + + return 0; + } + + // ---------------------------------------------------------------------------- // If the class defines a gc function, then call it. // ---------------------------------------------------------------------------- *************** *** 575,583 **** void* key = wxlua_touserdata(L, 1, true); - //wxPrintf(wxT("__gcClass '%s' %p\n"), wxlState.GetLuaTagName(*wxlClass->class_tag).c_str(), key); - //wxCHECK_MSG(key != 0, 0, wxT("NULL user data in wxluabind_gc_wxLuaBindClass")); - // clean up the rest of this, this won't error if the key doesn't exist ! wxluaO_removetrackedobject(L, key, wxLUA_DELETE_CLEAR_OBJECT); } --- 598,603 ---- void* key = wxlua_touserdata(L, 1, true); // clean up the rest of this, this won't error if the key doesn't exist ! wxluaO_deletegcobject(L, key, wxLUA_DELETE_REMOVE_OBJECT); } Index: wxlcallb.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlcallb.cpp,v retrieving revision 1.49 retrieving revision 1.50 diff -C2 -d -r1.49 -r1.50 *** wxlcallb.cpp 10 Dec 2007 05:39:10 -0000 1.49 --- wxlcallb.cpp 13 Dec 2007 00:47:51 -0000 1.50 *************** *** 230,236 **** { // clear the metatable for the copy of the we are tracking (clears it for all copies too) ! wxluaO_cleartrackedmetatable(m_wxlState.GetLuaState(), m_window); // Now remove the object since it's gone ! m_wxlState.RemoveTrackedObject(m_window, wxLUA_CLEAR_TRACKED_OBJECT|wxLUA_CLEAR_DERIVED_METHODS); // Clear our own pointer to this window m_wxlState.RemoveTrackedWindow(m_window); --- 230,236 ---- { // clear the metatable for the copy of the we are tracking (clears it for all copies too) ! wxluaO_deletegcobject(m_wxlState.GetLuaState(), m_window, wxLUA_REMOVE_OBJECT); // Now remove the object since it's gone ! m_wxlState.DeleteGCObject(m_window, wxLUA_REMOVE_OBJECT); // Clear our own pointer to this window m_wxlState.RemoveTrackedWindow(m_window); Index: wxlua_bind.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlua_bind.cpp,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** wxlua_bind.cpp 10 Dec 2007 05:39:10 -0000 1.15 --- wxlua_bind.cpp 13 Dec 2007 00:47:52 -0000 1.16 *************** *** 749,762 **** static wxLuaBindCFunc s_wxluafunc_wxLua_function_GetTrackedTopLevelWindows[1] = {{ wxLua_function_GetTrackedTopLevelWindows, WXLUAMETHOD_CFUNCTION, 0, 0, s_wxluaargArray_None }}; ! // %override wxLua_function_GetTrackedUserData // %function LuaTable GetTrackedUserData() ! static int LUACALL wxLua_function_GetTrackedUserData(lua_State *L) { ! wxLuaState wxlState(L); ! wxlua_pushwxArrayStringtable(L, wxlState.GetTrackedObjectStrings()); return 1; } ! static wxLuaBindCFunc s_wxluafunc_wxLua_function_GetTrackedUserData[1] = {{ wxLua_function_GetTrackedUserData, WXLUAMETHOD_CFUNCTION, 0, 0, s_wxluaargArray_None }}; // %override wxLua_function_GetTrackedWindows --- 749,761 ---- static wxLuaBindCFunc s_wxluafunc_wxLua_function_GetTrackedTopLevelWindows[1] = {{ wxLua_function_GetTrackedTopLevelWindows, WXLUAMETHOD_CFUNCTION, 0, 0, s_wxluaargArray_None }}; ! // %override wxLua_function_GetTrackedUserdata // %function LuaTable GetTrackedUserData() ! static int LUACALL wxLua_function_GetTrackedUserdata(lua_State *L) { ! wxlua_pushwxArrayStringtable(L, wxluaO_getgcobjectstrings(L)); return 1; } ! static wxLuaBindCFunc s_wxluafunc_wxLua_function_GetTrackedUserdata[1] = {{ wxLua_function_GetTrackedUserdata, WXLUAMETHOD_CFUNCTION, 0, 0, s_wxluaargArray_None }}; // %override wxLua_function_GetTrackedWindows *************** *** 890,894 **** { "GetTrackedEventCallbacks", WXLUAMETHOD_CFUNCTION, s_wxluafunc_wxLua_function_GetTrackedEventCallbacks, 1, NULL }, { "GetTrackedTopLevelWindows", WXLUAMETHOD_CFUNCTION, s_wxluafunc_wxLua_function_GetTrackedTopLevelWindows, 1, NULL }, ! { "GetTrackedUserData", WXLUAMETHOD_CFUNCTION, s_wxluafunc_wxLua_function_GetTrackedUserData, 1, NULL }, { "GetTrackedWindows", WXLUAMETHOD_CFUNCTION, s_wxluafunc_wxLua_function_GetTrackedWindows, 1, NULL }, { "iswxluatype", WXLUAMETHOD_CFUNCTION, s_wxluafunc_wxLua_function_iswxluatype, 1, NULL }, --- 889,893 ---- { "GetTrackedEventCallbacks", WXLUAMETHOD_CFUNCTION, s_wxluafunc_wxLua_function_GetTrackedEventCallbacks, 1, NULL }, { "GetTrackedTopLevelWindows", WXLUAMETHOD_CFUNCTION, s_wxluafunc_wxLua_function_GetTrackedTopLevelWindows, 1, NULL }, ! { "GetTrackedUserdata", WXLUAMETHOD_CFUNCTION, s_wxluafunc_wxLua_function_GetTrackedUserdata, 1, NULL }, { "GetTrackedWindows", WXLUAMETHOD_CFUNCTION, s_wxluafunc_wxLua_function_GetTrackedWindows, 1, NULL }, { "iswxluatype", WXLUAMETHOD_CFUNCTION, s_wxluafunc_wxLua_function_iswxluatype, 1, NULL }, |