From: John L. <jr...@us...> - 2007-06-12 00:08:47
|
Update of /cvsroot/wxlua/wxLua/modules/wxlua/src In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv4216/wxLua/modules/wxlua/src Modified Files: wxlbind.cpp wxlcallb.cpp wxlstate.cpp Log Message: Change wxLuaState::AddTrackedWindow to take a wxObject and figure out inside if it's a window Change the nomenclature "enum" to "integer" as the integer data type Change "base_"XXX to "_"XXX for base class function calls Add a test function to wxLuaPrintout to really check if virtual functions work More fixes to samples for binding changes Index: wxlstate.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlstate.cpp,v retrieving revision 1.106 retrieving revision 1.107 diff -C2 -d -r1.106 -r1.107 *** wxlstate.cpp 11 Jun 2007 03:58:10 -0000 1.106 --- wxlstate.cpp 12 Jun 2007 00:08:42 -0000 1.107 *************** *** 338,342 **** // pop the table and set it as the metatable for the newuserdata if (lua_setmetatable(L, -2) == 0) ! wxlua_terror(L, "wxLua: Unable to set metatable"); else return true; --- 338,342 ---- // pop the table and set it as the metatable for the newuserdata if (lua_setmetatable(L, -2) == 0) ! wxlua_terror(L, "wxLua: Unable to set metatable in tpushusertag."); else [...1320 lines suppressed...] int invalidArg = 0; --- 3529,3532 ---- *************** *** 3505,3508 **** --- 3536,3542 ---- int lua_argStart = 0; + // don't remove the table, but do skip past it when counting args + bool remove_table = wxluabind_removetableforcall(GetLuaState(), true); + if (remove_table) { *************** *** 3634,3637 **** --- 3668,3672 ---- { // we have to count the methods that are displayed to find the one that failed + // since we're failing anyway, we don't need this to be fast method = wxlMethod; int i_func = 0; Index: wxlbind.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlbind.cpp,v retrieving revision 1.69 retrieving revision 1.70 diff -C2 -d -r1.69 -r1.70 *** wxlbind.cpp 11 Jun 2007 03:58:10 -0000 1.69 --- wxlbind.cpp 12 Jun 2007 00:08:42 -0000 1.70 *************** *** 27,36 **** int LUACALL wxluabind_wxLuaBinding_index(lua_State* L); - // Binding tags are generated as positive tag id automatically when bound - // so we set the inbuilt lua arg tags to negative values - // - // note that -1 is use as initialiser for class tags - // and 0 is used as an end marker for tag array that - // represents prototypes argument types wxLuaArgTag s_wxluaargArray_None[1] = {0}; --- 27,30 ---- *************** *** 47,51 **** int s_wxluaarg_UserData = WXLUAARG_UserData; // raw data int s_wxluaarg_LuaThread = WXLUAARG_LuaThread; ! int s_wxluaarg_Enum = WXLUAARG_Enum; //----------------------------------------------------------------------------- --- 41,45 ---- int s_wxluaarg_UserData = WXLUAARG_UserData; // raw data int s_wxluaarg_LuaThread = WXLUAARG_LuaThread; ! int s_wxluaarg_Integer = WXLUAARG_Integer; //----------------------------------------------------------------------------- *************** *** 68,72 **** } - // A wxLuaFunction object is being garbage collected. int LUACALL wxlua_gc_wxLuaFunction(lua_State *L) { --- 62,65 ---- *************** *** 74,79 **** wxCHECK_MSG(wxlState.Ok(), 0, wxT("Invalid wxLuaState")); ! if (lua_isuserdata(L, 1) && (lua_islightuserdata(L, 1) == 0) && ! (wxlState.ttag(1) == wxlState.GetwxLuaFunctionTag())) { wxLuaFunction *wxlFunction = (wxLuaFunction *)wxlState.ttouserdata(1, true); --- 67,71 ---- wxCHECK_MSG(wxlState.Ok(), 0, wxT("Invalid wxLuaState")); ! if (wxlua_iswxuserdata(L, 1) && (wxlState.ttag(1) == wxlState.GetwxLuaFunctionTag())) { wxLuaFunction *wxlFunction = (wxLuaFunction *)wxlState.ttouserdata(1, true); *************** *** 84,88 **** } - // Handler for the 'function' tag method. int LUACALL wxlua_call_wxLuaFunction(lua_State *L) { --- 76,79 ---- *************** *** 90,100 **** wxCHECK_MSG(wxlState.Ok(), 0, wxT("Invalid wxLuaState")); ! if (lua_isuserdata(L, 1) && (lua_islightuserdata(L, 1) == 0) && ! (wxlState.ttag(1) == wxlState.GetwxLuaFunctionTag())) { wxLuaFunction *wxlFunction = (wxLuaFunction *)wxlState.ttouserdata(1, false); // remove the userdata *this from the stack ! // can't do this for static and nonstatic overloaded functions //if (wxlFunction->m_wxlMethod && WXLUA_HASBIT(wxlFunction->m_wxlMethod->type, WXLUAMETHOD_STATIC)) // lua_remove(L, 1); --- 81,90 ---- wxCHECK_MSG(wxlState.Ok(), 0, wxT("Invalid wxLuaState")); ! if (wxlua_iswxuserdata(L, 1) && (wxlState.ttag(1) == wxlState.GetwxLuaFunctionTag())) { wxLuaFunction *wxlFunction = (wxLuaFunction *)wxlState.ttouserdata(1, false); // remove the userdata *this from the stack ! // can't do this when there's both static and nonstatic overloaded functions //if (wxlFunction->m_wxlMethod && WXLUA_HASBIT(wxlFunction->m_wxlMethod->type, WXLUAMETHOD_STATIC)) // lua_remove(L, 1); *************** *** 115,126 **** { // set up the reference to the item on the stack ! m_iReference = m_wxlState->tinsert(stack_idx); } wxLuaObject::~wxLuaObject() { ! // If a refererence exists, remove it, don't bother if lua is being closed ! if ((m_iReference != LUA_NOREF) && m_wxlState->Ok() && !m_wxlState->IsClosing()) ! m_wxlState->tremove(m_iReference); delete m_wxlState; --- 105,116 ---- { // set up the reference to the item on the stack ! m_reference = m_wxlState->tinsert(stack_idx); } wxLuaObject::~wxLuaObject() { ! // If a refererence exists, remove it, but don't bother if lua is being closed ! if ((m_reference != LUA_NOREF) && m_wxlState->Ok() && !m_wxlState->IsClosing()) ! m_wxlState->tremove(m_reference); delete m_wxlState; *************** *** 167,171 **** return true; } ! else if (m_wxlState->tget(m_iReference)) return true; --- 157,161 ---- return true; } ! else if (m_wxlState->tget(m_reference)) return true; *************** *** 176,186 **** { wxCHECK_RET(m_wxlState->Ok(), wxT("Invalid wxLuaState")); ! if (m_wxlState->Ok() && (m_iReference != LUA_NOREF)) // FIXME should this error out? ! m_wxlState->tremove(m_iReference); ! m_iReference = LUA_NOREF; if (m_wxlState->Ok()) ! m_iReference = m_wxlState->tinsert(stack_idx); } --- 166,176 ---- { wxCHECK_RET(m_wxlState->Ok(), wxT("Invalid wxLuaState")); ! if (m_wxlState->Ok() && (m_reference != LUA_NOREF)) // FIXME should this error out? ! m_wxlState->tremove(m_reference); ! m_reference = LUA_NOREF; if (m_wxlState->Ok()) ! m_reference = m_wxlState->tinsert(stack_idx); } *************** *** 188,192 **** { wxCHECK_MSG(m_wxlState->Ok(), false, wxT("Invalid wxLuaState")); ! if (m_wxlState->Ok() && (m_iReference != LUA_NOREF) && GetObject()) { m_bool = (lua_toboolean(m_wxlState->GetLuaState(), -1) != 0); --- 178,182 ---- { wxCHECK_MSG(m_wxlState->Ok(), false, wxT("Invalid wxLuaState")); ! if (m_wxlState->Ok() && (m_reference != LUA_NOREF) && GetObject()) { m_bool = (lua_toboolean(m_wxlState->GetLuaState(), -1) != 0); *************** *** 200,204 **** { wxCHECK_MSG(m_wxlState->Ok(), false, wxT("Invalid wxLuaState")); ! if (m_wxlState->Ok() && (m_iReference != LUA_NOREF) && GetObject()) { m_int = (int) lua_tonumber(m_wxlState->GetLuaState(), -1); --- 190,194 ---- { wxCHECK_MSG(m_wxlState->Ok(), false, wxT("Invalid wxLuaState")); ! if (m_wxlState->Ok() && (m_reference != LUA_NOREF) && GetObject()) { m_int = (int) lua_tonumber(m_wxlState->GetLuaState(), -1); *************** *** 212,216 **** { wxCHECK_MSG(m_wxlState->Ok(), false, wxT("Invalid wxLuaState")); ! if (m_wxlState->Ok() && (m_iReference != LUA_NOREF) && GetObject()) { m_string = lua2wx(lua_tostring(m_wxlState->GetLuaState(), -1)); --- 202,206 ---- { wxCHECK_MSG(m_wxlState->Ok(), false, wxT("Invalid wxLuaState")); ! if (m_wxlState->Ok() && (m_reference != LUA_NOREF) && GetObject()) { m_string = lua2wx(lua_tostring(m_wxlState->GetLuaState(), -1)); *************** *** 225,229 **** { wxCHECK_MSG(m_wxlState->Ok(), false, wxT("Invalid wxLuaState")); ! if (m_wxlState->Ok() && (m_iReference != LUA_NOREF) && GetObject()) { m_wxlState->GetwxArrayInt(-1, m_arrayInt); --- 215,219 ---- { wxCHECK_MSG(m_wxlState->Ok(), false, wxT("Invalid wxLuaState")); ! if (m_wxlState->Ok() && (m_reference != LUA_NOREF) && GetObject()) { m_wxlState->GetwxArrayInt(-1, m_arrayInt); *************** *** 253,257 **** wxCHECK_MSG(wxlState.Ok(), 0, wxT("Invalid wxLuaState")); - int retVal = 0; wxLuaBindClass *wxlClass = (wxLuaBindClass *)lua_touserdata(L, lua_upvalueindex(1)); --- 243,246 ---- *************** *** 259,264 **** long key = -1; ! if ((wxlClass != NULL) && lua_isuserdata(L, 1) && ! (lua_islightuserdata(L, 1) == 0) && (wxlState.ttag(1) == *wxlClass->class_tag)) { key = (long)wxlState.ttouserdata(1, true); --- 248,252 ---- long key = -1; ! if ((wxlClass != NULL) && wxlua_iswxuserdata(L, 1) && (wxlState.ttag(1) == *wxlClass->class_tag)) { key = (long)wxlState.ttouserdata(1, true); *************** *** 267,271 **** //tracked = ! wxlState.RemoveTrackedObject((void*)key, true); // delete from m_pTrackedList wxlState.RemoveDerivedMethod((void*)key); } --- 255,259 ---- //tracked = ! wxlState.RemoveTrackedObject((void*)key, true); wxlState.RemoveDerivedMethod((void*)key); } *************** *** 274,278 **** // lua2wx(wxlClass ? wxlClass->name : "").c_str(), wxlClass ? *wxlClass->class_tag : 0, (int)L, key, (int)tracked, retVal); ! return retVal; } --- 262,266 ---- // lua2wx(wxlClass ? wxlClass->name : "").c_str(), wxlClass ? *wxlClass->class_tag : 0, (int)L, key, (int)tracked, retVal); ! return 0; } *************** *** 287,293 **** // ---------------------------------------------------------------------------- - #define CALL_BASECLASS_FUNC "base_" - #define CALL_BASECLASS_FUNC_LEN 5 - int LUACALL wxluabind_getTableFunc(lua_State *L) { --- 275,278 ---- *************** *** 300,304 **** // called as a function() or a .member? ! // See below, if base_XXX is called then we set this flag so that // the called function knows to call the base class instead of recalling // the lua function and recursing. --- 285,289 ---- // called as a function() or a .member? ! // See below, if _XXX is called then we set this flag so that // the called function knows to call the base class instead of recalling // the lua function and recursing. *************** *** 309,315 **** bool found = false; int result = 0; ! wxLuaBindClass *wxlClass = (wxLuaBindClass *)lua_touserdata(L, lua_upvalueindex(1)); ! const char *name = "{unknown}"; ! wxCharBuffer funcName; // debugging code for the table function, see print statement below --- 294,299 ---- bool found = false; int result = 0; ! wxLuaBindClass *wxlClass = (wxLuaBindClass *)lua_touserdata(L, lua_upvalueindex(1)); ! const char *name = NULL; // debugging code for the table function, see print statement below *************** *** 319,333 **** //int init_class_tag = wxlClass ? *wxlClass->class_tag : -1; ! if ((wxlClass != NULL) && lua_isuserdata(L, 1) && ! (lua_islightuserdata(L, 1) == 0) && (wxlState.ttag(1) == *wxlClass->class_tag)) { void *pObject = wxlState.ttouserdata(1); ! funcName = lua_tostring(L, 2); // make a copy of the string ! name = funcName.data(); ! callbase = (memcmp(name, CALL_BASECLASS_FUNC, CALL_BASECLASS_FUNC_LEN) == 0); if (callbase) ! name += CALL_BASECLASS_FUNC_LEN; // skip past "base_" else { --- 303,315 ---- //int init_class_tag = wxlClass ? *wxlClass->class_tag : -1; ! if ((wxlClass != NULL) && wxlua_iswxuserdata(L, 1) && (wxlState.ttag(1) == *wxlClass->class_tag)) { void *pObject = wxlState.ttouserdata(1); ! name = lua_tostring(L, 2); // make a copy of the string ! callbase = name[0] == '_'; if (callbase) ! name++; // skip past "_"FunctionName else { *************** *** 386,392 **** } ! //if (lua2wx(funcName).Find(wxT("OnBeginDocument")) != -1) // wxPrintf(wxT("wxluabind_getTableFunc func '%s' wxlClass %d '%s', userdata %d, lightuserdata %d, ttag %d, class_tag %d lua_State %d wxLuaStateRefData %d call base %d\n"), ! // lua2wx(funcName).c_str(), (long)wxlClass, wxlClass ? lua2wx(wxlClass->name).c_str() : wxT(""), init_isuserdata, init_islightuserdata, init_ttag, init_class_tag, (long)L, (long)wxlState.GetRefData(), (int)wxlState.GetCallBaseClassFunction()); if (!found) --- 368,374 ---- } ! //if (lua2wx(name).Find(wxT("OnBeginDocument")) != -1) // wxPrintf(wxT("wxluabind_getTableFunc func '%s' wxlClass %d '%s', userdata %d, lightuserdata %d, ttag %d, class_tag %d lua_State %d wxLuaStateRefData %d call base %d\n"), ! // lua2wx(name).c_str(), (long)wxlClass, wxlClass ? lua2wx(wxlClass->name).c_str() : wxT(""), init_isuserdata, init_islightuserdata, init_ttag, init_class_tag, (long)L, (long)wxlState.GetRefData(), (int)wxlState.GetCallBaseClassFunction()); if (!found) *************** *** 415,421 **** //wxPrintf(wxT("wxluabind_setTableFunc '%s'\n"), lua2wx(name).c_str()); ! if ((wxlClass != NULL) && lua_isuserdata(L, 1) && ! (lua_islightuserdata(L, 1) == 0) && ! (wxlState.ttag(1) == *wxlClass->class_tag)) { // See if there is a WXLUAMETHOD_SETPROP in the wxLuaBindClass's wxLuaBindMethods --- 397,401 ---- //wxPrintf(wxT("wxluabind_setTableFunc '%s'\n"), lua2wx(name).c_str()); ! if ((wxlClass != NULL) && wxlua_iswxuserdata(L, 1) && (wxlState.ttag(1) == *wxlClass->class_tag)) { // See if there is a WXLUAMETHOD_SETPROP in the wxLuaBindClass's wxLuaBindMethods Index: wxlcallb.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlcallb.cpp,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** wxlcallb.cpp 11 Jun 2007 03:58:10 -0000 1.30 --- wxlcallb.cpp 12 Jun 2007 00:08:42 -0000 1.31 *************** *** 26,42 **** IMPLEMENT_ABSTRACT_CLASS(wxLuaCallback, wxObject) ! wxLuaCallback::wxLuaCallback(const wxLuaState& state, int lua_func_stack_idx, wxWindowID winId, wxWindowID lastId, ! wxEventType eventType, wxEvtHandler *pEvtHandler) ! : wxObject(), m_wxlState(state), ! m_pHandler(pEvtHandler), m_id(winId), m_lastId(lastId), ! m_eventType(eventType) { wxCHECK_RET(m_wxlState.Ok(), wxT("Invalid wxLuaState")); ! // create a reference to the lua function m_routine = m_wxlState.tinsert(lua_func_stack_idx); ! pEvtHandler->Connect( winId, lastId, eventType, (wxObjectEventFunction)&wxLuaCallback::EventHandler, this); --- 26,55 ---- IMPLEMENT_ABSTRACT_CLASS(wxLuaCallback, wxObject) ! wxLuaCallback::wxLuaCallback(const wxLuaState& wxlState, int lua_func_stack_idx, wxWindowID winId, wxWindowID lastId, ! wxEventType eventType, wxEvtHandler *evtHandler) ! : wxObject(), m_wxlState(wxlState), ! m_evtHandler(evtHandler), m_id(winId), m_lastId(lastId), ! m_wxlBindEvent(NULL) ! //m_eventType(eventType) { wxCHECK_RET(m_wxlState.Ok(), wxT("Invalid wxLuaState")); ! m_wxlBindEvent = wxlState.GetLuaEvent(eventType); ! ! if (m_wxlBindEvent == NULL) ! { ! // Do not install this invalid or unknown event type since we won't know ! // what wxEvent type class to use and someone probably made a mistake. ! wxString msg = wxString::Format(wxT("Invalid or unknown wxEventType : %d, winIds %d %d."), ! (int)eventType, winId, lastId); ! m_wxlState.terror(msg); ! return; ! } ! ! // create a reference to the lua event handler function m_routine = m_wxlState.tinsert(lua_func_stack_idx); ! m_evtHandler->Connect(winId, lastId, eventType, (wxObjectEventFunction)&wxLuaCallback::EventHandler, this); *************** *** 58,62 **** void wxLuaCallback::EventHandler(wxEvent& event) { ! // This is the wxLuaCallback to use, NOT "this" wxLuaCallback *theCallback = (wxLuaCallback *) event.m_callbackUserData; --- 71,75 ---- void wxLuaCallback::EventHandler(wxEvent& event) { ! // This is the wxLuaCallback to use, NOT "this" since "this" is a central event handler function wxLuaCallback *theCallback = (wxLuaCallback *) event.m_callbackUserData; *************** *** 68,71 **** --- 81,85 ---- wxlState.SetInEventType(event.GetEventType()); + // If this is a wxWindow being destroyed, clear out all callbacks to it for safety if (event.GetEventType() == wxEVT_DESTROY) { *************** *** 83,89 **** while (node) { ! wxLuaCallback *pCallback = (wxLuaCallback *)node->GetData(); ! if ((pCallback != NULL) && (pCallback->GetEvtHandler() == evtHandler)) { // delete the reference to all other handlers that are cleared --- 97,103 ---- while (node) { ! wxLuaCallback *wxlCallback = (wxLuaCallback *)node->GetData(); ! if ((wxlCallback != NULL) && (wxlCallback->GetEvtHandler() == evtHandler)) { // delete the reference to all other handlers that are cleared *************** *** 92,96 **** wxlState.GetTrackedCallbackList()->Erase(pc_node); ! pCallback->ClearwxLuaState(); } else --- 106,110 ---- wxlState.GetTrackedCallbackList()->Erase(pc_node); ! wxlCallback->ClearwxLuaState(); } else *************** *** 104,108 **** } ! void wxLuaCallback::CallFunction(wxEvent *pEvent) { // Cannot call it if Lua is gone or the interpreter has been destroyed --- 118,122 ---- } ! void wxLuaCallback::CallFunction(wxEvent *event) { // Cannot call it if Lua is gone or the interpreter has been destroyed *************** *** 116,133 **** wxLuaState wxlState(m_wxlState); ! int eventClassTag = wxlState.GetwxEventTag(); // get the s_wxluatag_wxEvent ! const wxLuaBindEvent *pLuaEvent = wxlState.GetLuaEvent(pEvent->GetEventType()); ! if (pLuaEvent) ! eventClassTag = *pLuaEvent->class_tag; ! lua_checkstack(wxlState.GetLuaState(), LUA_MINSTACK); ! int oldTop = lua_gettop(wxlState.GetLuaState()); if (wxlState.tget(m_routine)) { ! lua_pushvalue(wxlState.GetLuaState(), LUA_GLOBALSINDEX); ! if (lua_setfenv(wxlState.GetLuaState(), -2) != 0) { ! wxlState.tpushusertag(pEvent, eventClassTag); wxlState.LuaPCall(1, 0); } --- 130,149 ---- wxLuaState wxlState(m_wxlState); ! int event_tag = 0; ! // If !m_wxlBindEvent, we would have errored in the constructor, but... ! if (m_wxlBindEvent != NULL) ! event_tag = *m_wxlBindEvent->class_tag; ! else ! event_tag = wxlState.GetwxEventTag(); // get the s_wxluatag_wxEvent ! wxlState.lua_CheckStack(LUA_MINSTACK); ! int oldTop = wxlState.lua_GetTop(); if (wxlState.tget(m_routine)) { ! wxlState.lua_PushValue(LUA_GLOBALSINDEX); ! if (wxlState.lua_SetFenv(-2) != 0) { ! wxlState.tpushusertag(event, event_tag); wxlState.LuaPCall(1, 0); } *************** *** 138,142 **** wxlState.terror("wxLua: wxEvtHandler::Connect in wxLuaCallback::CallFunction: function has been garbage collected."); ! lua_settop(wxlState.GetLuaState(), oldTop); } --- 154,158 ---- wxlState.terror("wxLua: wxEvtHandler::Connect in wxLuaCallback::CallFunction: function has been garbage collected."); ! wxlState.lua_SetTop(oldTop); // pop function from the stack (if it's there) } *************** *** 146,170 **** IMPLEMENT_ABSTRACT_CLASS(wxLuaWinDestroyCallback, wxObject) ! wxLuaWinDestroyCallback::wxLuaWinDestroyCallback(const wxLuaState& state, ! wxWindowID id, wxEvtHandler *pHandler, int iTag) ! :wxObject(), m_wxlState(state), ! m_pHandler(pHandler), m_id(id) { wxCHECK_RET(m_wxlState.Ok(), wxT("Invalid wxLuaState")); - lua_State *L = m_wxlState.GetLuaState(); // allocate a LUA proxy for the object ! const void **ptr = (const void **)lua_newuserdata(L, sizeof(void *)); if (ptr != NULL) { // save the address of the object in the proxy ! *ptr = pHandler; ! // and set the metatable of the proxy if (m_wxlState.tget(iTag)) { ! if (lua_setmetatable(L, -2) == 0) m_wxlState.terror("wxLua: Unable to set metatable of proxy in wxLuaWinDestroyCallback."); } --- 162,185 ---- IMPLEMENT_ABSTRACT_CLASS(wxLuaWinDestroyCallback, wxObject) ! wxLuaWinDestroyCallback::wxLuaWinDestroyCallback(const wxLuaState& wxlState, ! wxWindowID id, wxEvtHandler *evtHandler, int iTag) ! :wxObject(), m_wxlState(wxlState), ! m_evtHandler(evtHandler), m_id(id) { wxCHECK_RET(m_wxlState.Ok(), wxT("Invalid wxLuaState")); // allocate a LUA proxy for the object ! const void **ptr = (const void **)m_wxlState.lua_NewUserdata(sizeof(void *)); if (ptr != NULL) { // save the address of the object in the proxy ! *ptr = evtHandler; ! // and set the metatable of the proxy to the wxLuaReferences registry table if (m_wxlState.tget(iTag)) { ! if (m_wxlState.lua_SetMetatable(-2) == 0) m_wxlState.terror("wxLua: Unable to set metatable of proxy in wxLuaWinDestroyCallback."); } *************** *** 174,182 **** { // create a reference to object ! lua_pushlightuserdata(L, pHandler); // key ! lua_pushvalue(L, -3); // value // save it in the destroy handler table ! lua_rawset(L, -3); ! lua_pop(L, 1); } --- 189,197 ---- { // create a reference to object ! m_wxlState.lua_PushLightUserdata(evtHandler); // key ! m_wxlState.lua_PushValue(-3); // value // save it in the destroy handler table ! m_wxlState.lua_RawSet(-3); ! m_wxlState.lua_Pop(1); // pop the table from GetLuaWinDestroyTableTag() } *************** *** 184,190 **** // connect the event handler ! pHandler->Connect(id, wxEVT_DESTROY, ! (wxObjectEventFunction)&wxLuaWinDestroyCallback::EventHandler, ! this); } else --- 199,205 ---- // connect the event handler ! m_evtHandler->Connect(id, wxEVT_DESTROY, ! (wxObjectEventFunction)&wxLuaWinDestroyCallback::EventHandler, ! this); } else *************** *** 203,207 **** { wxLuaWinDestroyCallback *theCallback = (wxLuaWinDestroyCallback *)event.m_callbackUserData; ! if (theCallback && (((wxEvtHandler*)event.GetEventObject()) == theCallback->m_pHandler)) { theCallback->OnDestroy(event); --- 218,222 ---- { wxLuaWinDestroyCallback *theCallback = (wxLuaWinDestroyCallback *)event.m_callbackUserData; ! if (theCallback && (((wxEvtHandler*)event.GetEventObject()) == theCallback->m_evtHandler)) { theCallback->OnDestroy(event); *************** *** 224,234 **** if (m_wxlState.tget(m_wxlState.GetLuaWinDestroyTableTag())) { - lua_State* L = m_wxlState.GetLuaState(); // clear the metatable reference in the lua proxy. ! lua_pushlightuserdata(L, m_pHandler); ! lua_rawget(L, -2); ! lua_pushnil(L); ! lua_setmetatable(L, -2); ! lua_pop(L, 2); } } --- 239,248 ---- if (m_wxlState.tget(m_wxlState.GetLuaWinDestroyTableTag())) { // clear the metatable reference in the lua proxy. ! m_wxlState.lua_PushLightUserdata(m_evtHandler); ! m_wxlState.lua_RawGet(-2); ! m_wxlState.lua_PushNil(); ! m_wxlState.lua_SetMetatable(-2); ! m_wxlState.lua_Pop(2); } } |