From: John L. <jr...@us...> - 2007-12-07 06:44:52
|
Update of /cvsroot/wxlua/wxLua/modules/wxlua/src In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv26745/wxLua/modules/wxlua/src Modified Files: wxlcallb.cpp wxlstate.cpp wxlua.cpp wxlua_bind.cpp Log Message: Rename wxlua_getwxstringtype wxlua_getwxStringtype to match other funcs. Fix bug (from w/ last commit) of using wrong key/value indexes in lua_next() loop Index: wxlua.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlua.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** wxlua.cpp 7 Dec 2007 02:13:14 -0000 1.5 --- wxlua.cpp 7 Dec 2007 06:44:47 -0000 1.6 *************** *** 90,96 **** static int LUACALL wxLua_wxLuaObject_GetObject(lua_State *L) { - wxLuaState wxlState(L); // get this ! wxLuaObject *self = (wxLuaObject *)wxlState.GetUserDataType(1, s_wxluatag_wxLuaObject); // call GetObject that push the item onto the stack, or nil if (self->GetObject()) --- 90,95 ---- static int LUACALL wxLua_wxLuaObject_GetObject(lua_State *L) { // get this ! wxLuaObject *self = (wxLuaObject *)wxluaT_getuserdatatype(L, 1, s_wxluatag_wxLuaObject); // call GetObject that push the item onto the stack, or nil if (self->GetObject()) *************** *** 108,114 **** static int LUACALL wxLua_wxLuaObject_SetObject(lua_State *L) { - wxLuaState wxlState(L); // get this ! wxLuaObject *self = (wxLuaObject *)wxlState.GetUserDataType(1, s_wxluatag_wxLuaObject); // call SetObject self->SetObject(1); --- 107,112 ---- static int LUACALL wxLua_wxLuaObject_SetObject(lua_State *L) { // get this ! wxLuaObject *self = (wxLuaObject *)wxluaT_getuserdatatype(L, 1, s_wxluatag_wxLuaObject); // call SetObject self->SetObject(1); *************** *** 141,151 **** wxluabind_removetableforcall(L); wxLuaState wxlState(L); wxLuaObject *returns; // call constructor returns = new wxLuaObject(wxlState, 1); // add to tracked memory list ! wxlState.AddTrackedObject(returns); // push the constructed class pointer ! wxlState.PushUserDataType(s_wxluatag_wxLuaObject, returns); // return the number of parameters return 1; --- 139,150 ---- wxluabind_removetableforcall(L); wxLuaState wxlState(L); + wxLuaObject *returns; // call constructor 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); // return the number of parameters return 1; Index: wxlstate.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlstate.cpp,v retrieving revision 1.146 retrieving revision 1.147 diff -C2 -d -r1.146 -r1.147 *** wxlstate.cpp 7 Dec 2007 02:24:56 -0000 1.146 --- wxlstate.cpp 7 Dec 2007 06:44:46 -0000 1.147 *************** *** 987,991 **** } ! wxString LUACALL wxlua_getwxstringtype(lua_State *L, int stack_idx) { if (wxlua_isstringtype(L, stack_idx)) --- 987,991 ---- } ! wxString LUACALL wxlua_getwxStringtype(lua_State *L, int stack_idx) { if (wxlua_isstringtype(L, stack_idx)) *************** *** 1156,1160 **** else if (wxlua_iswxstringtype(L, -1)) { ! ((wxArrayString&)arr).Add(wxlua_getwxstringtype(L, -1)); ++count; --- 1156,1160 ---- else if (wxlua_iswxstringtype(L, -1)) { ! ((wxArrayString&)arr).Add(wxlua_getwxStringtype(L, -1)); ++count; *************** *** 1845,1852 **** { // value = -1, key = -2, table = -3 ! wxLuaCallback* cb = (wxLuaCallback*)lua_touserdata(L, -1); ! wxCHECK_RET(cb, wxT("Invalid wxLuaCallback")); ! if (cb && (cb->GetwxLuaState().GetRefData() != this)) // don't unref us ! cb->ClearwxLuaState(); lua_pop(L, 1); // pop value, lua_next will pop key at end --- 1845,1850 ---- { // value = -1, key = -2, table = -3 ! wxLuaCallback* cb = (wxLuaCallback*)lua_touserdata(L, -2); ! cb->ClearwxLuaState(); lua_pop(L, 1); // pop value, lua_next will pop key at end *************** *** 1860,1863 **** --- 1858,1862 ---- // ---------------------------------------------------------------------- + // These should already be gone from wxLuaCleanupWindows, make sure... lua_pushlightuserdata(L, &wxlua_lreg_windestroycallbacks_key); // push key *************** *** 1868,1877 **** { // value = -1, key = -2, table = -3 ! if (lua_type(L, -2) == LUA_TNUMBER) { ! wxLuaWinDestroyCallback* cb = (wxLuaWinDestroyCallback*)lua_touserdata(L, -1); ! wxCHECK_RET(cb, wxT("Invalid wxLuaWinDestroyCallback")); ! if (cb && (cb->GetwxLuaState().GetRefData() != this)) // don't unref us ! cb->ClearwxLuaState(); } --- 1867,1874 ---- { // value = -1, key = -2, table = -3 ! if (lua_type(L, -1) == LUA_TNUMBER) { ! wxLuaWinDestroyCallback* cb = (wxLuaWinDestroyCallback*)lua_touserdata(L, -2); ! cb->ClearwxLuaState(); } *************** *** 1892,1896 **** if (it != s_wxHashMapLuaState.end()) { - //wxPrintf(wxT("GetLuaStateRefData L %d data %d\n"), (int)L, (int)it->second); return wxLuaState(*it->second); } --- 1889,1892 ---- *************** *** 2099,2104 **** if (m_refData == NULL) return; - //wxPrintf(wxT("wxLuaState::Destroy RefCount %d\n"), GetRefData()->GetRefCount()); - // we don't want recursion in UnRef and wxlua_garbageCollect if (GetRefData()->GetRefCount() == 1) --- 2095,2098 ---- *************** *** 2783,2786 **** --- 2777,2783 ---- 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 *************** *** 2939,2943 **** { wxCHECK_MSG(Ok(), wxEmptyString, wxT("Invalid wxLuaState")); ! return wxlua_getwxstringtype(M_WXLSTATEDATA->m_lua_State, stack_idx); } bool wxLuaState::GetBooleanType(int stack_idx) --- 2936,2940 ---- { wxCHECK_MSG(Ok(), wxEmptyString, wxT("Invalid wxLuaState")); ! return wxlua_getwxStringtype(M_WXLSTATEDATA->m_lua_State, stack_idx); } bool wxLuaState::GetBooleanType(int stack_idx) Index: wxlcallb.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlcallb.cpp,v retrieving revision 1.47 retrieving revision 1.48 diff -C2 -d -r1.47 -r1.48 *** wxlcallb.cpp 7 Dec 2007 02:13:14 -0000 1.47 --- wxlcallb.cpp 7 Dec 2007 06:44:46 -0000 1.48 *************** *** 70,77 **** } wxString wxLuaCallback::GetInfo() const { ! return wxString::Format(wxT("%s(%d) -> wxLuaCallback(%p, ids %d, %d)|wxEvtHandler(%p) -> %s"), ! lua2wx(m_wxlBindEvent ? m_wxlBindEvent->name : "?").c_str(), (int)GetEventType(), this, m_id, m_last_id, m_evtHandler, m_evtHandler->GetClassInfo()->GetClassName()); --- 70,82 ---- } + void wxLuaCallback::ClearwxLuaState() + { + m_wxlState.UnRef(); + } + wxString wxLuaCallback::GetInfo() const { ! return wxString::Format(wxT("%s(%d) -> wxLuaCallback(%p, ids %d, %d)|wxEvtHandler(%p) -> %s"), ! lua2wx(m_wxlBindEvent ? m_wxlBindEvent->name : "?").c_str(), (int)GetEventType(), this, m_id, m_last_id, m_evtHandler, m_evtHandler->GetClassInfo()->GetClassName()); *************** *** 184,187 **** --- 189,197 ---- } + void wxLuaWinDestroyCallback::ClearwxLuaState() + { + m_wxlState.UnRef(); + } + wxString wxLuaWinDestroyCallback::GetInfo() const { *************** *** 190,195 **** winName = m_window->GetClassInfo()->GetClassName(); ! return wxString::Format(wxT("%s(%p, id=%d)|wxLuaDestroyCallback(%p)"), ! winName.c_str(), m_window, m_window ? m_window->GetId() : -1, this); } --- 200,205 ---- winName = m_window->GetClassInfo()->GetClassName(); ! return wxString::Format(wxT("%s(%p, id=%d)|wxLuaDestroyCallback(%p)"), ! winName.c_str(), m_window, m_window ? m_window->GetId() : -1, this); } *************** *** 240,247 **** { // value = -1, key = -2, table = -3 ! wxLuaCallback* wxlCallback = (wxLuaCallback*)lua_touserdata(L, -1); wxCHECK_RET(wxlCallback, wxT("Invalid wxLuaCallback")); ! if (wxlCallback->GetEvtHandler() == evtHandler) { // remove the ref to the routine since we're clearing the wxLuaState --- 250,258 ---- { // value = -1, key = -2, table = -3 ! wxLuaCallback* wxlCallback = (wxLuaCallback*)lua_touserdata(L, -2); wxCHECK_RET(wxlCallback, wxT("Invalid wxLuaCallback")); ! if ((wxlCallback->GetEvtHandler() == evtHandler) || ! (wxlCallback->GetEvtHandler() == (wxEvtHandler*)m_window)) { // remove the ref to the routine since we're clearing the wxLuaState Index: wxlua_bind.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlua_bind.cpp,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** wxlua_bind.cpp 7 Dec 2007 02:13:14 -0000 1.13 --- wxlua_bind.cpp 7 Dec 2007 06:44:47 -0000 1.14 *************** *** 136,145 **** static int LUACALL wxLua_function_CompileLuaScript(lua_State *L) { - wxLuaState wxlState(L); int returns; // const wxString fileName ! const wxString fileName = wxlState.GetwxStringType(2); // const wxString luaScript ! const wxString luaScript = wxlState.GetwxStringType(1); wxString errMsg; int line_num = -1; --- 136,144 ---- static int LUACALL wxLua_function_CompileLuaScript(lua_State *L) { int returns; // const wxString fileName ! const wxString fileName = wxlua_getwxStringtype(L, 2); // const wxString luaScript ! const wxString luaScript = wxlua_getwxStringtype(L, 1); wxString errMsg; int line_num = -1; *************** *** 148,152 **** // push the result number lua_pushnumber(L, returns); ! wxlState.lua_PushString(errMsg); lua_pushnumber(L, line_num); return 3; --- 147,151 ---- // push the result number lua_pushnumber(L, returns); ! wxlua_pushwxString(L, errMsg); lua_pushnumber(L, line_num); return 3; *************** *** 199,205 **** int LUACALL wxluabind_wxLuaBindCFunc__index(lua_State* L) { - wxLuaState wxlState(L); - wxCHECK_MSG(wxlState.Ok(), 0, wxT("Invalid wxLuaState")); - void **ptr = (void **)lua_touserdata(L, 1); wxLuaBindCFunc* wxlCFunc= (wxLuaBindCFunc*)*ptr; --- 198,201 ---- *************** *** 283,289 **** int LUACALL wxluabind_wxLuaBindMethod__index(lua_State* L) { - wxLuaState wxlState(L); - wxCHECK_MSG(wxlState.Ok(), 0, wxT("Invalid wxLuaState")); - void **ptr = (void **)lua_touserdata(L, 1); wxLuaBindMethod* wxlMethod = (wxLuaBindMethod*)*ptr; --- 279,282 ---- *************** *** 388,394 **** int LUACALL wxluabind_wxLuaBindClass__index(lua_State* L) { - wxLuaState wxlState(L); - wxCHECK_MSG(wxlState.Ok(), 0, wxT("Invalid wxLuaState")); - void **ptr = (void **)lua_touserdata(L, 1); wxLuaBindClass* wxlClass = (wxLuaBindClass*)*ptr; --- 381,384 ---- *************** *** 450,457 **** if (wxlClass->classInfo) { ! const wxLuaBindClass* classInfoClass = wxlState.GetBindClass("wxClassInfo"); if (classInfoClass) { ! wxlState.PushUserDataType(*classInfoClass->class_tag, wxlClass->classInfo); return 1; } --- 440,447 ---- if (wxlClass->classInfo) { ! const wxLuaBindClass* classInfoClass = wxluaT_getclass(L, "wxClassInfo"); if (classInfoClass) { ! wxluaT_pushuserdatatype(L, *classInfoClass->class_tag, wxlClass->classInfo); return 1; } *************** *** 535,541 **** int LUACALL wxluabind_wxLuaBinding__index(lua_State* L) { - wxLuaState wxlState(L); - wxCHECK_MSG(wxlState.Ok(), 0, wxT("Invalid wxLuaState")); - void **ptr = (void **)lua_touserdata(L, 1); wxLuaBinding* wxlBinding = (wxLuaBinding*)*ptr; --- 525,528 ---- *************** *** 718,724 **** lua_pushstring(L, "object"); if (wxlObject->objPtr != 0) ! wxlState.wxluaT_PushUserTag(wxlObject->objPtr, *wxlObject->class_tag, false); else ! wxlState.wxluaT_PushUserTag(*wxlObject->pObjPtr, *wxlObject->class_tag, false); lua_rawset(L, -3); --- 705,711 ---- lua_pushstring(L, "object"); if (wxlObject->objPtr != 0) ! wxluaT_pushusertag(L, wxlObject->objPtr, *wxlObject->class_tag, false); else ! wxluaT_pushusertag(L, *wxlObject->pObjPtr, *wxlObject->class_tag, false); lua_rawset(L, -3); *************** *** 807,812 **** static int LUACALL wxLua_function_type(lua_State *L) { - wxLuaState wxlState(L); - int ltype = lua_type(L, 1); const char* ltypename = lua_typename(L, ltype); --- 794,797 ---- *************** *** 822,826 **** wxluaarg_tag = wxlua_getwxluatype(ltype); ! wxString tagName = wxlState.GetLuaTagName(wxluaarg_tag); //wxlua_getwxluatypename(wxluaarg_tag); // push the results --- 807,811 ---- wxluaarg_tag = wxlua_getwxluatype(ltype); ! wxString tagName = wxluaT_gettagname(L, wxluaarg_tag); //wxlua_getwxluatypename(wxluaarg_tag); // push the results *************** *** 841,852 **** static int LUACALL wxLua_function_typename(lua_State *L) { - wxLuaState wxlState(L); wxString returns; // int wxluaarg_tag int wxluaarg_tag = (int)wxlua_getnumbertype(L, 1); // call wxlua_getwxluatypename ! returns = wxlState.GetLuaTagName(wxluaarg_tag); //wxlua_getwxluatypename(wxluaarg_tag); // push the result string ! wxlState.lua_PushString(returns); return 1; --- 826,836 ---- static int LUACALL wxLua_function_typename(lua_State *L) { wxString returns; // int wxluaarg_tag int wxluaarg_tag = (int)wxlua_getnumbertype(L, 1); // call wxlua_getwxluatypename ! returns = wxluaT_gettagname(L, wxluaarg_tag); //wxlua_getwxluatypename(wxluaarg_tag); // push the result string ! wxlua_pushwxString(L, returns); return 1; |