From: John L. <jr...@us...> - 2005-12-30 04:36:08
|
Update of /cvsroot/wxlua/wxLua/modules/wxlua/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11092/wxLua/modules/wxlua/src Modified Files: internal.cpp wxlbind.cpp wxlstate.cpp Log Message: use wxLuaState in addToTrackedMemory, now called wxLua_addToTrackedMemory better docs in wxlstate header rem out wxPrintf debug code fix error recreating wxLuaState, need to Destroy before calling UnRef Index: internal.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/internal.cpp,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** internal.cpp 29 Dec 2005 20:06:47 -0000 1.23 --- internal.cpp 30 Dec 2005 04:35:59 -0000 1.24 *************** *** 630,657 **** } ! // The following functions support memory allocated for objects in ! // the Lua system. ! ! bool LUACALL removeTrackedMemory(lua_State *L, void *pObject, bool fDelete) ! { ! wxLuaState wxlState(L); ! wxCHECK_MSG(wxlState.Ok(), false, wxT("Invalid wxLuaState")); ! return wxlState.removeTrackedMemory(pObject, fDelete); ! } ! ! void LUACALL addToTrackedMemoryList(lua_State *L, wxObject *pObject) { - wxLuaState wxlState(L); - wxCHECK_RET(wxlState.Ok(), wxT("Invalid wxLuaState")); wxlState.addToTrackedMemoryList(pObject); } - void LUACALL addToTrackedWindowList(lua_State *L, wxWindow *pWindow) - { - wxLuaState wxlState(L); - wxCHECK_RET(wxlState.Ok(), wxT("Invalid wxLuaState")); - wxlState.addToTrackedWindowList(pWindow); - } - // Return a pointer to the object that corresponds to the specified stack // index and tag --- 630,638 ---- } ! void LUACALL wxLua_addToTrackedMemoryList(wxLuaState& wxlState, wxObject *pObject) { wxlState.addToTrackedMemoryList(pObject); } // Return a pointer to the object that corresponds to the specified stack // index and tag *************** *** 1269,1273 **** wxLuaState wxlState(L); if (wxlState.Ok()) ! wxlState.DisplayError(errorMsg); lua_settop(L, top); status = 0; --- 1250,1254 ---- wxLuaState wxlState(L); if (wxlState.Ok()) ! wxlState.SendErrorEvent(errorMsg); lua_settop(L, top); status = 0; Index: wxlstate.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlstate.cpp,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** wxlstate.cpp 29 Dec 2005 20:10:19 -0000 1.17 --- wxlstate.cpp 30 Dec 2005 04:35:59 -0000 1.18 *************** *** 42,46 **** #include "wxlua/include/wxlstate.h" #include "wxlua/include/wxlcallb.h" - //#include "wxbind/include/wxbind.h" #include "wxlua/include/wxlintrp.h" #include "wxlua/include/internal.h" --- 42,45 ---- *************** *** 116,120 **** // ---------------------------------------------------------------------------- - int LuaPrint( lua_State *L ) { --- 115,118 ---- *************** *** 283,287 **** wxlState.GetLuaDebugHook()); ! terror(L, wx2lua(wxlState.GetDebugHookBreakMessage())); return; } --- 281,285 ---- wxlState.GetLuaDebugHook()); ! wxlState.terror(wx2lua(wxlState.GetDebugHookBreakMessage())); return; } *************** *** 297,301 **** wxlState.SendEvent( event ); if (event.m_stop_interpreter) ! terror(L, "Interpreter stopped"); } --- 295,299 ---- wxlState.SendEvent( event ); if (event.m_stop_interpreter) ! wxlState.terror("Interpreter stopped"); } *************** *** 535,539 **** m_windowList.DeleteContents(false); ! m_bindings.DeleteContents(true); // we add new copies of the bindings wxLuaBindingList::Node *node; --- 533,537 ---- m_windowList.DeleteContents(false); ! m_bindings.DeleteContents(true); // we add "new" copies of the bindings wxLuaBindingList::Node *node; *************** *** 541,545 **** { wxLuaBinding* binding = node->GetData(); ! m_bindings.Append(binding->Clone()); } } --- 539,543 ---- { wxLuaBinding* binding = node->GetData(); ! m_bindings.Append(binding->Clone()); // append the "new" binding } } *************** *** 560,563 **** --- 558,563 ---- wxLuaStateRefData::~wxLuaStateRefData() { + wxCHECK_RET(m_lua_State == NULL, wxT("You must ALWAYS call wxLuaState::Destroy and not wxObject::UnRef")); + // no events here, the handler may already be gone m_evtHandler = NULL; *************** *** 626,630 **** ClearCallbacks(); ! if (closeLua) { UnRegisterBindings(); --- 626,630 ---- ClearCallbacks(); ! if (closeLua && (m_lua_State != NULL)) { UnRegisterBindings(); *************** *** 724,727 **** --- 724,728 ---- void wxLuaState::Create( const wxLuaState& wxlState ) { + Destroy(); Ref(wxlState); } *************** *** 777,781 **** { wxCHECK_MSG(L != NULL, false, wxT("Invalid lua_State")); ! if (GetRefData() != NULL) Destroy(); if (type == WXLUASTATE_ATTACH) --- 778,782 ---- { wxCHECK_MSG(L != NULL, false, wxT("Invalid lua_State")); ! Destroy(); if (type == WXLUASTATE_ATTACH) *************** *** 823,827 **** void wxLuaState::Destroy() { ! if (!GetRefData()) return; // we don't want recursion in UnRef and wxLua_lua_garbageCollect --- 824,828 ---- void wxLuaState::Destroy() { ! if (m_refData == NULL) return; // we don't want recursion in UnRef and wxLua_lua_garbageCollect *************** *** 872,876 **** } ! void wxLuaState::DisplayError( const wxString &errorMsg ) { wxLuaEvent event(wxEVT_LUA_ERROR, GetId(), *this); --- 873,877 ---- } ! void wxLuaState::SendErrorEvent( const wxString &errorMsg ) { wxLuaEvent event(wxEVT_LUA_ERROR, GetId(), *this); *************** *** 879,883 **** } ! bool wxLuaState::CheckRunError(int rc) { wxCHECK_MSG(Ok(), false, wxT("Invalid wxLuaState")); --- 880,884 ---- } ! bool wxLuaState::CheckAndSendRunErrorEvent(int rc) { wxCHECK_MSG(Ok(), false, wxT("Invalid wxLuaState")); *************** *** 898,901 **** --- 899,903 ---- { wxCHECK_RET(Ok(), wxT("Invalid wxLuaState")); + if (GetEventHandler()) { *************** *** 918,922 **** M_WXLSTATEDATA->m_is_running = false; if (!M_WXLSTATEDATA->m_debug_hook_break) ! (void)CheckRunError(ret_val); M_WXLSTATEDATA->m_debug_hook_break = false; --- 920,924 ---- M_WXLSTATEDATA->m_is_running = false; if (!M_WXLSTATEDATA->m_debug_hook_break) ! CheckAndSendRunErrorEvent(ret_val); M_WXLSTATEDATA->m_debug_hook_break = false; *************** *** 937,941 **** // if it's been stopped then don't send this error message, already sent stopped one if (!M_WXLSTATEDATA->m_debug_hook_break) ! (void)CheckRunError(ret_val); M_WXLSTATEDATA->m_debug_hook_break = false; --- 939,943 ---- // if it's been stopped then don't send this error message, already sent stopped one if (!M_WXLSTATEDATA->m_debug_hook_break) ! CheckAndSendRunErrorEvent(ret_val); M_WXLSTATEDATA->m_debug_hook_break = false; *************** *** 955,959 **** if (!M_WXLSTATEDATA->m_debug_hook_break) ! (void)CheckRunError(ret_val); M_WXLSTATEDATA->m_debug_hook_break = false; --- 957,961 ---- if (!M_WXLSTATEDATA->m_debug_hook_break) ! CheckAndSendRunErrorEvent(ret_val); M_WXLSTATEDATA->m_debug_hook_break = false; *************** *** 1273,1276 **** --- 1275,1284 ---- } + void wxLuaState::addToTrackedMemoryList(int obj_ptr, wxObject *pObject) + { + wxCHECK_RET(Ok() && pObject, wxT("Invalid wxLuaState or wxObject to track")); + M_WXLSTATEDATA->m_pTrackedList->Put(obj_ptr, pObject); + } + bool wxLuaState::removeTrackedMemory(void *pObject, bool fDelete) { *************** *** 1546,1555 **** lua_State* L = M_WXLSTATEDATA->m_lua_State; ! wxPrintf(wxT("wxLuaState::ttag %d"), index); int tag = TLUA_NOTAG; if (lua_getmetatable(L, index) != 0) { ! wxPrintf(wxT(" has metatable")); lua_pushliteral(L, "tag"); lua_rawget(L, -2); --- 1554,1563 ---- lua_State* L = M_WXLSTATEDATA->m_lua_State; ! //wxPrintf(wxT("wxLuaState::ttag %d"), index); int tag = TLUA_NOTAG; if (lua_getmetatable(L, index) != 0) { ! //wxPrintf(wxT(" has metatable")); lua_pushliteral(L, "tag"); lua_rawget(L, -2); *************** *** 1557,1565 **** { tag = (int) lua_tonumber(L, -1); ! wxPrintf(wxT(" and is number %d"), tag); } lua_pop(L, 2); } ! wxPrintf(wxT("\n")); return tag; } --- 1565,1573 ---- { tag = (int) lua_tonumber(L, -1); ! //wxPrintf(wxT(" and is number %d"), tag); } lua_pop(L, 2); } ! //wxPrintf(wxT("\n")); return tag; } *************** *** 2171,2177 **** errorMsg += wxT("\n"); ! DisplayError(errorMsg); lua_settop(L, top); ! status = 0; } --- 2179,2185 ---- errorMsg += wxT("\n"); ! SendErrorEvent(errorMsg); lua_settop(L, top); ! status = 0; // FIXME - does this make sense to zero it here? } Index: wxlbind.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlbind.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** wxlbind.cpp 29 Dec 2005 20:07:58 -0000 1.11 --- wxlbind.cpp 30 Dec 2005 04:35:59 -0000 1.12 *************** *** 132,137 **** } ! wxPrintf(wxT("wxLua_lua_getTableFunc '%s' pClass %d, userdata %d, lightuserdata %d, ttag %d, class_tag %d lua_State %d wxLuaStateRefData %d\n"), ! lua2wx(cpIndex).c_str(), (long)pClass, init_isuserdata, init_islightuserdata, init_ttag, init_class_tag, (long)L, (long)wxlState.GetRefData()); if (!fFound) --- 132,137 ---- } ! // wxPrintf(wxT("wxLua_lua_getTableFunc '%s' pClass %d, userdata %d, lightuserdata %d, ttag %d, class_tag %d lua_State %d wxLuaStateRefData %d\n"), ! // lua2wx(cpIndex).c_str(), (long)pClass, init_isuserdata, init_islightuserdata, init_ttag, init_class_tag, (long)L, (long)wxlState.GetRefData()); if (!fFound) |