From: John L. <jr...@us...> - 2008-01-04 00:21:19
|
Update of /cvsroot/wxlua/wxLua/modules/wxlua/src In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv6007/wxLua/modules/wxlua/src Modified Files: wxlbind.cpp wxlcallb.cpp wxlstate.cpp Log Message: Fix typos in comments Only need wxWindow = wxLuaWinDestroyCallback in the wxlua_lreg_windestroycallbacks_key table Index: wxlstate.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlstate.cpp,v retrieving revision 1.157 retrieving revision 1.158 diff -C2 -d -r1.157 -r1.158 *** wxlstate.cpp 3 Jan 2008 00:05:58 -0000 1.157 --- wxlstate.cpp 4 Jan 2008 00:21:08 -0000 1.158 *************** *** 1,4 **** ///////////////////////////////////////////////////////////////////////////// ! // Purpose: wxWidgets interface to Lua // Author: Ray Gilbert, John Labenski, J Winwood (Reuben Thomas for bitlib at bottom) // Created: 14/11/2001 --- 1,5 ---- ///////////////////////////////////////////////////////////////////////////// ! // Name: wxlstate.cpp ! // Purpose: wxLuaState, a wxWidgets interface to Lua // Author: Ray Gilbert, John Labenski, J Winwood (Reuben Thomas for bitlib at bottom) // Created: 14/11/2001 *************** *** 2053,2061 **** { // value = -1, key = -2, table = -3 ! if (lua_type(L, -1) == LUA_TNUMBER) ! { ! wxLuaWinDestroyCallback* cb = (wxLuaWinDestroyCallback*)lua_touserdata(L, -2); ! cb->ClearwxLuaState(); ! } lua_pop(L, 1); // pop value, lua_next will pop key at end --- 2054,2059 ---- { // value = -1, key = -2, table = -3 ! wxLuaWinDestroyCallback* cb = (wxLuaWinDestroyCallback*)lua_touserdata(L, -1); ! cb->ClearwxLuaState(); lua_pop(L, 1); // pop value, lua_next will pop key at end *************** *** 2892,2902 **** lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push value (table) - // Note: We push t[callback] = 1 so that we can determine later - // what datatypes the key and values are. - - lua_pushlightuserdata(L, callback); // push key - lua_pushnumber(L, 1); // push value - lua_rawset(L, -3); // set t[key] = value; pops key and value - lua_pushlightuserdata(L, callback->GetWindow()); // push key lua_pushlightuserdata(L, callback); // push value --- 2890,2893 ---- *************** *** 2913,2920 **** lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push value (table) - lua_pushlightuserdata(L, callback); // push key - lua_pushnil(L); // push value - lua_rawset(L, -3); // set t[key] = value; pops key and value - lua_pushlightuserdata(L, callback->GetWindow()); // push key lua_pushnil(L); // push value --- 2904,2907 ---- *************** *** 2940,2950 **** { // value = -1, key = -2, table = -3 ! if (lua_type(L, -2) == LUA_TUSERDATA) ! { ! wxLuaWinDestroyCallback* wxlDestroyCallBack = (wxLuaWinDestroyCallback*)lua_touserdata(L, -2); ! wxCHECK_MSG(wxlDestroyCallBack, names, wxT("Invalid wxLuaWinDestroyCallback")); ! names.Add(wxlDestroyCallBack->GetInfo()); ! } lua_pop(L, 1); // pop value, lua_next will pop key at end --- 2927,2934 ---- { // value = -1, key = -2, table = -3 ! wxLuaWinDestroyCallback* wxlDestroyCallBack = (wxLuaWinDestroyCallback*)lua_touserdata(L, -1); ! wxCHECK_MSG(wxlDestroyCallBack, names, wxT("Invalid wxLuaWinDestroyCallback")); ! names.Add(wxlDestroyCallBack->GetInfo()); lua_pop(L, 1); // pop value, lua_next will pop key at end Index: wxlbind.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlbind.cpp,v retrieving revision 1.110 retrieving revision 1.111 diff -C2 -d -r1.110 -r1.111 *** wxlbind.cpp 22 Dec 2007 06:07:15 -0000 1.110 --- wxlbind.cpp 4 Jan 2008 00:21:08 -0000 1.111 *************** *** 1,3 **** --- 1,4 ---- ///////////////////////////////////////////////////////////////////////////// + // Name: wxlbind.cpp // Purpose: wxLuaBinding // Author: Ray Gilbert, John Labenski, J Winwood Index: wxlcallb.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlcallb.cpp,v retrieving revision 1.54 retrieving revision 1.55 diff -C2 -d -r1.54 -r1.55 *** wxlcallb.cpp 3 Jan 2008 00:05:58 -0000 1.54 --- wxlcallb.cpp 4 Jan 2008 00:21:08 -0000 1.55 *************** *** 27,31 **** wxLuaEventCallback::wxLuaEventCallback() ! : m_luafunc_ref(0), m_wxlState(wxNullLuaState), m_evtHandler(NULL), m_id(wxID_ANY), m_last_id(wxID_ANY), m_wxlBindEvent(NULL) --- 27,31 ---- wxLuaEventCallback::wxLuaEventCallback() ! : m_luafunc_ref(0), //m_wxlState(wxNullLuaState), m_evtHandler(NULL), m_id(wxID_ANY), m_last_id(wxID_ANY), m_wxlBindEvent(NULL) *************** *** 48,51 **** --- 48,52 ---- wxEventType eventType, wxEvtHandler *evtHandler) { + // Assert too since these errors are serious and not just bad Lua code. wxCHECK_MSG(evtHandler != NULL, wxT("Invalid wxEvtHandler in wxLuaEventCallback::Connect()"), wxT("Invalid wxEvtHandler in wxLuaEventCallback::Connect()")); wxCHECK_MSG((m_evtHandler == NULL) && (m_luafunc_ref == 0), wxT("Attempting to reconnect a wxLuaEventCallback"), wxT("Attempting to reconnect a wxLuaEventCallback")); *************** *** 59,66 **** m_wxlBindEvent = wxlState.GetBindEvent(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. return wxString::Format(wxT("wxLua: Invalid or unknown wxEventType for wxEvtHandler::Connect() : %d, winIds %d, %d."), (int)eventType, win_id, last_id); --- 60,67 ---- m_wxlBindEvent = wxlState.GetBindEvent(eventType); + // 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. if (m_wxlBindEvent == NULL) { return wxString::Format(wxT("wxLua: Invalid or unknown wxEventType for wxEvtHandler::Connect() : %d, winIds %d, %d."), (int)eventType, win_id, last_id); *************** *** 75,78 **** --- 76,80 ---- // Note: We use the callback userdata and not the event sink since the event sink // requires a wxEvtHandler object which is a fairly large class. + // The userdata is also deleted for us which makes m_evtHandler->Connect(win_id, last_id, eventType, (wxObjectEventFunction)&wxLuaEventCallback::OnAllEvents, *************** *** 98,106 **** wxEventType evtType = event.GetEventType(); ! // Get the wxLuaEventCallback to use, NOT "this" since "this" is a central event handler function wxLuaEventCallback *theCallback = (wxLuaEventCallback *)event.m_callbackUserData; wxCHECK_RET(theCallback != NULL, wxT("Invalid wxLuaEventCallback in wxEvent user data")); ! // Ok if !Ok() since the wxLuaState may been cleared during shutdown or after a destroy event wxLuaState wxlState(theCallback->GetwxLuaState()); if (wxlState.Ok()) --- 100,109 ---- wxEventType evtType = event.GetEventType(); ! // Get the wxLuaEventCallback instance to use which is NOT "this" since ! // "this" is a central event handler function. i.e. this != theCallback wxLuaEventCallback *theCallback = (wxLuaEventCallback *)event.m_callbackUserData; wxCHECK_RET(theCallback != NULL, wxT("Invalid wxLuaEventCallback in wxEvent user data")); ! // Not an error if !Ok(), the wxLuaState is cleared during shutdown or after a destroy event. wxLuaState wxlState(theCallback->GetwxLuaState()); if (wxlState.Ok()) *************** *** 120,124 **** // Cannot call it if Lua is gone or the interpreter has been destroyed // This can happen when the program exists since windows may be destroyed ! // after Lua has been deleted if (!m_wxlState.Ok()) return; --- 123,127 ---- // Cannot call it if Lua is gone or the interpreter has been destroyed // This can happen when the program exists since windows may be destroyed ! // after Lua has been deleted. if (!m_wxlState.Ok()) return; *************** *** 127,133 **** wxLuaState wxlState(m_wxlState); ! int event_wxl_type = 0; ! // If !m_wxlBindEvent, we would have errored in Connect(), but... if (m_wxlBindEvent != NULL) { --- 130,136 ---- wxLuaState wxlState(m_wxlState); ! int event_wxl_type = WXLUA_TUNKNOWN; ! // If !m_wxlBindEvent, we would have errored in Connect(), but don't crash... if (m_wxlBindEvent != NULL) { *************** *** 144,152 **** event_wxl_type = *wxlClass->wxluatype; else ! event_wxl_type = g_wxluatag_wxEvent; // get the s_wxluatag_wxEvent } } else ! event_wxl_type = g_wxluatag_wxEvent; // get the s_wxluatag_wxEvent // Should never get here, but error out in case we do --- 147,155 ---- event_wxl_type = *wxlClass->wxluatype; else ! event_wxl_type = g_wxluatag_wxEvent; // get the g_wxluatag_wxEvent } } else ! event_wxl_type = g_wxluatag_wxEvent; // get the g_wxluatag_wxEvent // Should never get here, but error out in case we do *************** *** 160,174 **** if (wxlState.lua_SetFenv(-2) != 0) { ! // don't track this since we don't own it ! // Tracking this causes clashes in the object registry table ! // since many can be created and deleted and the mem address is resused by C++. wxlState.wxluaT_PushUserDataType(event, event_wxl_type, false); ! wxlState.LuaPCall(1, 0); } else ! wxlState.wxlua_Error("wxLua: wxEvtHandler::Connect in wxLuaEventCallback::CallFunction: function is not a Lua function."); } else ! wxlState.wxlua_Error("wxLua: wxEvtHandler::Connect in wxLuaEventCallback::CallFunction: function has been garbage collected."); wxlState.lua_SetTop(oldTop); // pop function from the stack (if it's there) --- 163,177 ---- if (wxlState.lua_SetFenv(-2) != 0) { ! // Don't track the wxEvent since we don't own it and tracking it ! // causes clashes in the object registry table since many can be ! // created and deleted and the mem address is resused by C++. wxlState.wxluaT_PushUserDataType(event, event_wxl_type, false); ! wxlState.LuaPCall(1, 0); // one input no returns } else ! wxlState.wxlua_Error("wxLua: wxEvtHandler::Connect() in wxLuaEventCallback::OnEvent(), function is not a Lua function."); } else ! wxlState.wxlua_Error("wxLua: wxEvtHandler::Connect() in wxLuaEventCallback::OnEvent(), function to call is not refed."); wxlState.lua_SetTop(oldTop); // pop function from the stack (if it's there) *************** *** 185,188 **** --- 188,192 ---- { wxCHECK_RET(m_wxlState.Ok(), wxT("Invalid wxLuaState")); + wxCHECK_RET(m_window != NULL, wxT("Invalid wxWindow")); m_wxlState.AddTrackedWinDestroyCallback(this); *************** *** 211,215 **** { wxString winName(wxT("wxWindow?")); ! if (m_window && m_window->GetClassInfo() && m_window->GetClassInfo()->GetClassName()) winName = m_window->GetClassInfo()->GetClassName(); --- 215,219 ---- { wxString winName(wxT("wxWindow?")); ! if (m_window && m_window->GetClassInfo()) winName = m_window->GetClassInfo()->GetClassName(); *************** *** 240,244 **** if (m_wxlState.Ok()) { ! // clear the metatable for the copy of the we are tracking (clears it for all copies too) wxluaO_untrackweakobject(m_wxlState.GetLuaState(), NULL, m_window); wxlua_removederivedmethods(m_wxlState.GetLuaState(), m_window); --- 244,248 ---- if (m_wxlState.Ok()) { ! // clear the metatable for all userdata we're tracking. wxluaO_untrackweakobject(m_wxlState.GetLuaState(), NULL, m_window); wxlua_removederivedmethods(m_wxlState.GetLuaState(), m_window); *************** *** 277,280 **** --- 281,287 ---- lua_pop(L, 1); // pop value + // The code below is the equivalent of this, but works while iterating + // "m_wxlState.RemoveTrackedEventCallback(wxlCallback);" + lua_pushvalue(L, -1); // copy key for next iteration lua_pushnil(L); |