From: John L. <jr...@us...> - 2007-06-25 23:04:07
|
Update of /cvsroot/wxlua/wxLua/modules/wxlua/src In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv10540/wxLua/modules/wxlua/src Modified Files: wxlbind.cpp wxlstate.cpp Log Message: Replace wxLuaState::GetCallBaseClassfunction with wxlua_getcallbaseclassfunction so we no longer need a wxLuaState in the __index func for class objects Better names for the metatable C functions Index: wxlstate.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlstate.cpp,v retrieving revision 1.117 retrieving revision 1.118 diff -C2 -d -r1.117 -r1.118 *** wxlstate.cpp 25 Jun 2007 19:44:54 -0000 1.117 --- wxlstate.cpp 25 Jun 2007 23:04:02 -0000 1.118 *************** *** 44,47 **** --- 44,49 ---- int wxlua_lreg_derivedmethods_key = WXLUA_LREG_DERIVED_METHODS; int wxlua_lreg_wxluastaterefdata_key = WXLUA_LREG_WXLUASTATEREFDATA; + int wxlua_lreg_callbaseclassfunc_key = WXLUA_LREG_CALLBASECLASSFUNC; + int wxlua_lreg_metatable_tag_key = WXLUA_METATABLE_TAG; int wxlua_lreg_metatable_class_key = WXLUA_METATABLE_CLASS; *************** *** 82,85 **** --- 84,89 ---- msg += lua2wx(s); lua_pop(L, 1); /* pop result */ + /* + // we do this now in wxluabind__tostring_wxLuaBindClass // if we know the type, add it *************** *** 94,97 **** --- 98,102 ---- } } + */ } *************** *** 834,838 **** //---------------------------------------------------------------------------- ! bool wxlua_setderivedmethod(lua_State* L, void *pObject, const char *method_name, wxLuaObject* wxlObj) { wxlua_pushkey_wxLuaDerivedMethods(L); --- 839,843 ---- //---------------------------------------------------------------------------- ! bool LUACALL wxlua_setderivedmethod(lua_State* L, void *pObject, const char *method_name, wxLuaObject* wxlObj) { wxlua_pushkey_wxLuaDerivedMethods(L); *************** *** 885,889 **** return true; } ! bool wxlua_hasderivedmethod(lua_State* L, void *pObject, const char *method_name, bool push_method) { bool found = false; --- 890,894 ---- return true; } ! bool LUACALL wxlua_hasderivedmethod(lua_State* L, void *pObject, const char *method_name, bool push_method) { bool found = false; *************** *** 929,933 **** return found; } ! bool wxlua_removederivedmethod(lua_State* L, void *pObject) { bool found = false; --- 934,938 ---- return found; } ! bool LUACALL wxlua_removederivedmethod(lua_State* L, void *pObject) { bool found = false; *************** *** 979,982 **** --- 984,1004 ---- } + bool LUACALL wxlua_getcallbaseclassfunction(lua_State*L) + { + wxlua_pushkey_CallBaseClassFunc(L); + lua_rawget( L, LUA_REGISTRYINDEX ); // pop key, push bool + bool call_base = (bool)lua_toboolean(L, -1); + lua_pop(L, 1); // pop bool + + return call_base; + } + + void LUACALL wxlua_setcallbaseclassfunction(lua_State*L, bool call_base) + { + wxlua_pushkey_CallBaseClassFunc(L); + lua_pushboolean(L, call_base); + lua_rawset( L, LUA_REGISTRYINDEX ); // pop key and bool + } + // ---------------------------------------------------------------------------- // wxFindWindowByPointer - find a window by it's pointer *************** *** 1109,1113 **** wxLuaStateData::wxLuaStateData() :m_bindings_registered(false), - m_callbase_func(false), m_inEventType(wxEVT_NULL), m_is_running(false), --- 1131,1134 ---- *************** *** 2009,2014 **** } ! tsettagmethod(g_wxluatag_wxLuaFunction, "__gc", wxlua_gc_wxLuaFunction); ! tsettagmethod(g_wxluatag_wxLuaFunction, "__call", wxlua_call_wxLuaFunction); // Finally - set the global tags from the bindings we've just installed --- 2030,2035 ---- } ! tsettagmethod(g_wxluatag_wxLuaFunction, "__gc", wxlua__gc_wxLuaFunction); ! tsettagmethod(g_wxluatag_wxLuaFunction, "__call", wxlua__call_wxLuaFunction); // Finally - set the global tags from the bindings we've just installed *************** *** 2142,2151 **** { wxCHECK_RET(Ok(), wxT("Invalid wxLuaState")); ! M_WXLSTATEDATA->m_wxlStateData->m_callbase_func = call_base; } bool wxLuaState::GetCallBaseClassFunction() { wxCHECK_MSG(Ok(), false, wxT("Invalid wxLuaState")); ! return M_WXLSTATEDATA->m_wxlStateData->m_callbase_func; } --- 2163,2172 ---- { wxCHECK_RET(Ok(), wxT("Invalid wxLuaState")); ! wxlua_setcallbaseclassfunction(M_WXLSTATEDATA->m_lua_State, call_base); } bool wxLuaState::GetCallBaseClassFunction() { wxCHECK_MSG(Ok(), false, wxT("Invalid wxLuaState")); ! return wxlua_getcallbaseclassfunction(M_WXLSTATEDATA->m_lua_State); } Index: wxlbind.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlbind.cpp,v retrieving revision 1.80 retrieving revision 1.81 diff -C2 -d -r1.80 -r1.81 *** wxlbind.cpp 25 Jun 2007 19:44:53 -0000 1.80 --- wxlbind.cpp 25 Jun 2007 23:04:02 -0000 1.81 *************** *** 69,73 **** } ! int LUACALL wxlua_gc_wxLuaFunction(lua_State *L) { // Sanity check, but this is only attached to a wxLuaFunction, so it has to be ok. --- 69,73 ---- } ! int LUACALL wxlua__gc_wxLuaFunction(lua_State *L) { // Sanity check, but this is only attached to a wxLuaFunction, so it has to be ok. *************** *** 81,85 **** } ! int LUACALL wxlua_call_wxLuaFunction(lua_State *L) { // Sanity check, but this is only attached to a wxLuaFunction, so it has to be ok. --- 81,85 ---- } ! int LUACALL wxlua__call_wxLuaFunction(lua_State *L) { // Sanity check, but this is only attached to a wxLuaFunction, so it has to be ok. *************** *** 88,96 **** wxLuaFunction *wxlFunction = (wxLuaFunction *)wxlua_ttouserdata(L, 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); - return wxlFunction->CallMethod(L); } --- 88,91 ---- *************** *** 248,252 **** // ---------------------------------------------------------------------------- ! int LUACALL wxluabind_gc_wxLuaBindClass(lua_State *L) { wxLuaBindClass *wxlClass = (wxLuaBindClass *)lua_touserdata(L, lua_upvalueindex(1)); --- 243,247 ---- // ---------------------------------------------------------------------------- ! int LUACALL wxluabind__gc_wxLuaBindClass(lua_State *L) { wxLuaBindClass *wxlClass = (wxLuaBindClass *)lua_touserdata(L, lua_upvalueindex(1)); *************** *** 276,284 **** // ---------------------------------------------------------------------------- ! int LUACALL wxluabind_index_wxLuaBindClass(lua_State *L) { - wxLuaState wxlState(L); - wxCHECK_MSG(wxlState.Ok(), 0, wxT("Invalid wxLuaState")); - // This function is called for the __index metable of the wxLua userdata // for class instances. The stack contains 1 = userdata, 2 = "FuncName" --- 271,276 ---- // ---------------------------------------------------------------------------- ! int LUACALL wxluabind__index_wxLuaBindClass(lua_State *L) { // This function is called for the __index metable of the wxLua userdata // for class instances. The stack contains 1 = userdata, 2 = "FuncName" *************** *** 289,294 **** // the called function knows to call the base class instead of recalling // the lua function and recursing. ! //wxCHECK_MSG(!wxlState.GetCallBaseClassFunction(), 0, wxT("Base class function call not reset")); ! wxlState.SetCallBaseClassFunction(false); bool callbase = false; --- 281,285 ---- // the called function knows to call the base class instead of recalling // the lua function and recursing. ! wxlua_setcallbaseclassfunction(L, false); bool callbase = false; *************** *** 333,337 **** found = true; result = 1; ! wxLuaFunction *wxlFunc = new wxLuaFunction(wxlMethod, wxlClass, pObject); wxlua_tpushusertag(L, wxlFunc, g_wxluatag_wxLuaFunction); } --- 324,328 ---- found = true; result = 1; ! wxLuaFunction *wxlFunc = new wxLuaFunction(wxlMethod, pObject); wxlua_tpushusertag(L, wxlFunc, g_wxluatag_wxLuaFunction); } *************** *** 363,372 **** // This MUST be reset to false in the base class function ! if (found && callbase) wxlState.SetCallBaseClassFunction(true); } } if (!found) ! wxlState.terror(wxString::Format(_("wxLua: Attempt to call an invalid method '%s'."), lua2wx(name).c_str())); return result; --- 354,363 ---- // This MUST be reset to false in the base class function ! if (found && callbase) wxlua_setcallbaseclassfunction(L, true); } } if (!found) ! wxlua_terror(L, wxString::Format(_("wxLua: Attempt to call an invalid method '%s'."), lua2wx(name).c_str())); return result; *************** *** 427,434 **** --- 418,456 ---- } + // ---------------------------------------------------------------------------- + // wxluabind__tostring_wxLuaBindClass + // ---------------------------------------------------------------------------- + + int LUACALL wxluabind__tostring_wxLuaBindClass(lua_State *L) + { + wxLuaState wxlState(L); + wxCHECK_MSG(wxlState.Ok(), 0, wxT("Invalid wxLuaState")); + + wxString str(wxT("Invalid wxLua userdata!")); // should never happen + + if (lua_isuserdata(L, 1)) + { + // this should be identical to Lua's tostring for a userdata + str = wxString::Format(wxT("userdata: %p"), lua_touserdata(L, 1)); + + int nTag = wxlua_ttag(L, 1); + if (nTag != WXLUA_NOTAG) + { + wxString name = wxlState.GetLuaTagName(nTag); + if (!name.IsEmpty()) + str += wxString::Format(wxT(" (%s)"), name.c_str()); + } + } + + lua_pushstring(L, wx2lua(str)); + return 1; + } + + // ---------------------------------------------------------------------------- // Use the pointer to this int as a special tag to know that __call has been // made on a table and that we want to remove the table for the bindings to // work. This is because lua always pushes the table on the stack if '.' or ':' // is used for the __call metamethod. + // ---------------------------------------------------------------------------- static int wxluabind_checkremovetable = 0; *************** *** 682,688 **** static const luaL_reg s_funcTable[] = { ! {"__gc", wxluabind_gc_wxLuaBindClass }, ! {"__index", wxluabind_index_wxLuaBindClass }, ! {"__newindex", wxluabind__newindex_wxLuaBindClass } }; static const size_t s_funcCount = sizeof(s_funcTable)/sizeof(s_funcTable[0]); --- 704,711 ---- static const luaL_reg s_funcTable[] = { ! {"__gc", wxluabind__gc_wxLuaBindClass }, ! {"__index", wxluabind__index_wxLuaBindClass }, ! {"__newindex", wxluabind__newindex_wxLuaBindClass }, ! {"__tostring", wxluabind__tostring_wxLuaBindClass } }; static const size_t s_funcCount = sizeof(s_funcTable)/sizeof(s_funcTable[0]); |