From: John L. <jr...@us...> - 2007-12-03 23:47:29
|
Update of /cvsroot/wxlua/wxLua/modules/wxlua/src In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv9980/wxLua/modules/wxlua/src Modified Files: wxlstate.cpp Log Message: Code cleanup in wxlstate.cpp Sort numeric debug items by number so you don't get 1,10,2,3,4... Index: wxlstate.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlstate.cpp,v retrieving revision 1.140 retrieving revision 1.141 diff -C2 -d -r1.140 -r1.141 *** wxlstate.cpp 30 Nov 2007 23:00:07 -0000 1.140 --- wxlstate.cpp 3 Dec 2007 23:47:24 -0000 1.141 *************** *** 43,46 **** --- 43,49 ---- // ---------------------------------------------------------------------------- + // The print function that we push into Lua replacing "print(...)" + // to generate wxLuaEvent(wxEVT_LUA_PRINT, ...) + // Code copied from Lua's luaB_print() function in lbaselib.c int LUACALL wxlua_printFunction( lua_State *L ) { *************** *** 54,58 **** for (i = 1; i <= n; i++) { - // code copied from luaB_print in lbaselib.c if (i > 1) msg.Append(wxT("\t")); // Lua uses a tab too in luaB_print --- 57,60 ---- *************** *** 84,158 **** } - #if 0 - // copied from the Lua 5.0.1 debug library - #define LEVELS1 12 /* size of the first part of the stack */ - #define LEVELS2 10 /* size of the second part of the stack */ - - //static lua_State *getthread (lua_State *L, int *arg) in ldblib.c - lua_State LUACALL *wxlua_getthread(lua_State *L, int *arg) { - if (lua_isthread(L, 1)) { - *arg = 1; - return lua_tothread(L, 1); - } - else { - *arg = 0; - return L; - } - } - - //static int db_errorfb (lua_State *L) in ldblib.c - static int LUACALL wxlua_tracebackFunction(lua_State *L) { - int level; - int firstpart = 1; /* still before eventual `...' */ - int arg; - lua_State *L1 = wxlua_getthread(L, &arg); - lua_Debug ar = INIT_LUA_DEBUG; - if (lua_isnumber(L, arg+2)) { - level = (int)lua_tointeger(L, arg+2); - lua_pop(L, 1); - } - else - level = (L == L1) ? 1 : 0; /* level 0 may be this own function */ - if (lua_gettop(L) == arg) - lua_pushliteral(L, ""); - else if (!lua_isstring(L, arg+1)) return 1; /* message is not a string */ - else lua_pushliteral(L, "\n"); - lua_pushliteral(L, "stack traceback:"); - while (lua_getstack(L1, level++, &ar)) { - if (level > LEVELS1 && firstpart) { - /* no more than `LEVELS2' more levels? */ - if (!lua_getstack(L1, level+LEVELS2, &ar)) - level--; /* keep going */ - else { - lua_pushliteral(L, "\n\t..."); /* too many levels */ - while (lua_getstack(L1, level+LEVELS2, &ar)) /* find last levels */ - level++; - } - firstpart = 0; - continue; - } - lua_pushliteral(L, "\n\t"); - lua_getinfo(L1, "Snl", &ar); - lua_pushfstring(L, "%s:", ar.short_src); - if (ar.currentline > 0) - lua_pushfstring(L, "line# %d:", ar.currentline); - if (*ar.namewhat != '\0') /* is there a name? */ - lua_pushfstring(L, " in function " LUA_QS, ar.name); - else { - if (*ar.what == 'm') /* main? */ - lua_pushfstring(L, " in main chunk"); - else if (*ar.what == 'C' || *ar.what == 't') - lua_pushliteral(L, " ?"); /* C function or tail call */ - else - lua_pushfstring(L, " in function <%s:%d>", - ar.short_src, ar.linedefined); - } - lua_concat(L, lua_gettop(L) - arg); - } - lua_concat(L, lua_gettop(L) - arg); - return 1; - } - #endif // 0 - void LUACALL wxlua_debugHookFunction(lua_State *L, lua_Debug *LDebug) { --- 86,89 ---- *************** *** 237,240 **** --- 168,173 ---- // ---------------------------------------------------------------------------- + #define ABS_LUA_STKIDX(n, added_items) ((n) > 0 ? (n) : (n)-(added_items)) + // Note about luaL_ref and luaL_unref. // ref creates integer numbers from 1 to ... *************** *** 247,323 **** int wxluaT_insert(lua_State* L, int stack_idx, const void* lightuserdata_reg_key) { ! if (lua_isnone(L, stack_idx)) // nothing on stack to insert ! return LUA_REFNIL; ! ! if (lua_isnil(L, stack_idx)) // don't bother inserting nil ! { ! lua_pop(L, 1); return LUA_REFNIL; - } ! lua_pushlightuserdata(L, (void*)lightuserdata_reg_key); // push name of table to get as key ! lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push result (the refs table) ! lua_pushvalue(L, stack_idx > 0 ? stack_idx : stack_idx-1); // push value to store ! int table_idx = luaL_ref(L, -2); // create unique integer reference ! // in our refs table ! // We also store the value for this table for faster lookup if (lightuserdata_reg_key == &wxlua_lreg_debug_refs_key) { ! lua_pushvalue(L, stack_idx > 0 ? stack_idx : stack_idx-1); // push value to store ! lua_pushnumber(L, table_idx); ! ! lua_rawset(L, -3); } ! lua_pop(L, 1); // pop refs table return table_idx; } ! bool wxluaT_remove(lua_State* L, int wxlref_index, const void* lightuserdata_reg_key) { ! if (wxlref_index == LUA_REFNIL) // nothing to remove ! return true; ! lua_pushlightuserdata(L, (void*)lightuserdata_reg_key); // push name of table to get as key ! lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push result (the refs table) if (lightuserdata_reg_key == &wxlua_lreg_debug_refs_key) { ! lua_pushnumber(L, wxlref_index); ! lua_rawget(L, -2); lua_pushnil(L); ! lua_rawset(L, -3); } ! luaL_unref(L, -1, wxlref_index); // remove key and value in refs table ! // note: this key will be used for the next wxluaT_insert ! lua_pop(L, 1); // pop the refs table return true; } ! bool LUACALL wxluaT_get(lua_State *L, int wxlref_index, const void* lightuserdata_reg_key) { ! if (wxlref_index == LUA_REFNIL) // nothing to get return false; ! lua_pushlightuserdata(L, (void*)lightuserdata_reg_key); // push name of table to get as key ! lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push result (the refs table) ! lua_rawgeti(L, -1, wxlref_index); // get table value at wxlref_index ! lua_remove(L, -2); // remove wxLua's registry table ! if (lua_isnil(L, -1)) // not a valid table key { ! lua_pop(L, 1); return false; } return true; // return if table has a valid value and it's on the stack } --- 180,251 ---- int wxluaT_insert(lua_State* L, int stack_idx, const void* lightuserdata_reg_key) { ! // nothing on stack to insert and don't bother inserting nil ! if (lua_isnoneornil(L, stack_idx)) return LUA_REFNIL; ! lua_pushlightuserdata(L, (void*)lightuserdata_reg_key); // push key ! lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push value (table) ! lua_pushvalue(L, ABS_LUA_STKIDX(stack_idx,1)); // push value to store ! int table_idx = luaL_ref(L, -2); // t[table_idx] = value; pops value ! // We also store t[value] = table_idx for this table for faster lookup if (lightuserdata_reg_key == &wxlua_lreg_debug_refs_key) { ! lua_pushvalue(L, ABS_LUA_STKIDX(stack_idx,1)); // push key ! lua_pushnumber(L, table_idx); // push value ! lua_rawset(L, -3); // set t[key] = value; pops key and value } ! lua_pop(L, 1); // pop table return table_idx; } ! bool wxluaT_remove(lua_State* L, int table_idx, const void* lightuserdata_reg_key) { ! if (table_idx == LUA_REFNIL) // nothing to remove ! return false; ! lua_pushlightuserdata(L, (void*)lightuserdata_reg_key); // push key ! lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push value (table) + // Also remove the t[value] = table_idx for this table if (lightuserdata_reg_key == &wxlua_lreg_debug_refs_key) { ! lua_pushnumber(L, table_idx); // push key ! lua_rawget(L, -2); // get t[key] = value; pop key, push value; lua_pushnil(L); ! lua_rawset(L, -3); // t[value] = nil; pops key and value } ! luaL_unref(L, -1, table_idx); // remove key and value in refs table ! // note: this key will be used for the next wxluaT_insert + lua_pop(L, 1); // pop table return true; } ! bool LUACALL wxluaT_get(lua_State *L, int table_idx, const void* lightuserdata_reg_key) { ! if (table_idx == LUA_REFNIL) // nothing to get return false; ! lua_pushlightuserdata(L, (void*)lightuserdata_reg_key); // push key ! lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push value (table) ! lua_rawgeti(L, -1, table_idx); // get t[table_idx] = value; push value ! if (lua_isnil(L, -1)) // not a valid table key { ! lua_pop(L, 2); // pop nil and table return false; } + lua_remove(L, -2); // remove table, leaving value on top + return true; // return if table has a valid value and it's on the stack } *************** *** 335,350 **** { lua_pushlightuserdata(L, &wxlua_lreg_objects_key); ! lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push result (the obj table) ! lua_pushlightuserdata(L, (void*)u); // key on Lua's userdata ! lua_rawget(L, -2); if (wxlua_iswxuserdata(L, -1)) { ! lua_remove(L, -2); // remove the obj table return true; } ! ! // pop the table and the nil. ! lua_pop(L, 2); } --- 263,277 ---- { lua_pushlightuserdata(L, &wxlua_lreg_objects_key); ! lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push value (the obj table) ! lua_pushlightuserdata(L, (void*)u); // push key ! lua_rawget(L, -2); // get t[key] value; pop key push value if (wxlua_iswxuserdata(L, -1)) { ! lua_remove(L, -2); // remove the obj table, leave value on the stack return true; } ! ! lua_pop(L, 2); // pop the table and the nil. } *************** *** 362,376 **** if (track) { ! lua_pushlightuserdata(L, &wxlua_lreg_objects_key); ! lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push result (the obj table) lua_pushlightuserdata(L, (void*)u); // key on the object since we can reuse the userdata ! lua_pushvalue(L, -3); // push the Lua userdata as the value (note: weak valued table) ! lua_rawset(L, -3); ! lua_pop(L, 1); // pop obj table } ! return true; } else --- 289,303 ---- if (track) { ! lua_pushlightuserdata(L, &wxlua_lreg_objects_key); // push key ! lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push value (the obj table) lua_pushlightuserdata(L, (void*)u); // key on the object since we can reuse the userdata ! lua_pushvalue(L, -3); // push the Lua userdata as the value (note: weak valued table) ! lua_rawset(L, -3); // t[key] = value; pops key and value ! lua_pop(L, 1); // pop obj table } ! return true; // leave value on the stack } else *************** *** 388,405 **** void LUACALL wxluaT_untrackuserdata(lua_State *L, const void *u) { ! lua_pushlightuserdata(L, &wxlua_lreg_objects_key); ! lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push result (the object table) ! lua_pushlightuserdata(L, (void*)u); ! lua_pushnil(L); // t["lightuserdata ptr"] = nil to remove it ! lua_rawset(L, -3); ! lua_pop(L, 1); // pop objects table } void LUACALL wxluaT_cleartrackedmetatable(lua_State *L, const void *u) { ! lua_pushlightuserdata(L, &wxlua_lreg_objects_key); ! lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push result (the object table) ! lua_pushlightuserdata(L, (void*)u); ! lua_rawget(L, -2); if (lua_isuserdata(L, -1)) --- 315,334 ---- void LUACALL wxluaT_untrackuserdata(lua_State *L, const void *u) { ! lua_pushlightuserdata(L, &wxlua_lreg_objects_key); // push key ! lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push value (the object table) ! ! lua_pushlightuserdata(L, (void*)u); // push key ! lua_pushnil(L); // push value ! lua_rawset(L, -3); // t[key] = nil; pops key and value ! lua_pop(L, 1); // pop objects table } void LUACALL wxluaT_cleartrackedmetatable(lua_State *L, const void *u) { ! lua_pushlightuserdata(L, &wxlua_lreg_objects_key); // push key ! lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push value (the object table) ! ! lua_pushlightuserdata(L, (void*)u); // push key ! lua_rawget(L, -2); // get t[key] = value; pop key push value if (lua_isuserdata(L, -1)) *************** *** 415,422 **** { int tag = WXLUA_NOTAG; if (lua_getmetatable(L, stack_idx) != 0) // see wxluaT_newtag { ! lua_pushlightuserdata(L, &wxlua_metatable_tag_key); // get t[tag_key] ! lua_rawget(L, -2); //if (lua_isnumber(L, -1)) // Note: lua_tonumber returns 0 == WXLUA_NOTAG if it's not a number tag = (int)lua_tonumber(L, -1); --- 344,353 ---- { int tag = WXLUA_NOTAG; + if (lua_getmetatable(L, stack_idx) != 0) // see wxluaT_newtag { ! lua_pushlightuserdata(L, &wxlua_metatable_tag_key); // push key ! lua_rawget(L, -2); // get t[key] = value; pop key push value ! //if (lua_isnumber(L, -1)) // Note: lua_tonumber returns 0 == WXLUA_NOTAG if it's not a number tag = (int)lua_tonumber(L, -1); *************** *** 424,427 **** --- 355,359 ---- lua_pop(L, 2); // pop metatable and tag number } + return tag; } *************** *** 444,453 **** int wxluaT_newtag(lua_State* L) { ! lua_newtable(L); // create a table for our new tag int tag = wxluaT_insert(L, -1, &wxlua_lreg_tags_key); // insert the table into the registry table ! lua_pushlightuserdata(L, &wxlua_metatable_tag_key); // add t[tag_key] = tag to new table ! lua_pushnumber(L, tag); ! lua_rawset(L, -3); return tag; // leave the table on the stack --- 376,385 ---- int wxluaT_newtag(lua_State* L) { ! lua_newtable(L); // create a table for our new tag int tag = wxluaT_insert(L, -1, &wxlua_lreg_tags_key); // insert the table into the registry table ! lua_pushlightuserdata(L, &wxlua_metatable_tag_key); // push key ! lua_pushnumber(L, tag); // push value ! lua_rawset(L, -3); // t[key] = value; pop key and value return tag; // leave the table on the stack *************** *** 458,465 **** if (wxluaT_get(L, tag, &wxlua_lreg_tags_key)) // get the metatable table from the wxLuaReferences registry table { ! if (!lua_setmetatable(L, -2)) // set it as the metatable of the object at the top of the stack ! wxlua_error(L, "wxLua: Unable to set metatable in wxluaT_settag."); ! else return true; } --- 390,397 ---- if (wxluaT_get(L, tag, &wxlua_lreg_tags_key)) // get the metatable table from the wxLuaReferences registry table { ! if (lua_setmetatable(L, -2)) // set it as the metatable of the object at the top of the stack return true; + else + wxlua_error(L, "wxLua: Unable to set metatable in wxluaT_settag."); } *************** *** 471,494 **** int tag = LUA_NOREF; ! lua_pushlightuserdata(L, (void*)lightuserdata_reg_key); // push name of table to get as key ! lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push result (the refs table) if (lightuserdata_reg_key == &wxlua_lreg_debug_refs_key) { ! lua_pushvalue(L, stack_idx > 0 ? stack_idx : stack_idx-1); // push value to compare - lua_rawget(L, -2); if (lua_isnumber(L, -1)) tag = (int)lua_tonumber(L, -1); ! lua_pop(L, 2); // pop number/nil and reg table } else { lua_pushnil(L); ! while (lua_next(L, -2) != 0) // ref table can have holes in it { ! // value = -1, key = -2, table = -3, object = -4 ! if (lua_equal(L, -1, -4)) { tag = (int)lua_tonumber(L, -2); --- 403,428 ---- int tag = LUA_NOREF; ! lua_pushlightuserdata(L, (void*)lightuserdata_reg_key); // push key ! lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push value (table) if (lightuserdata_reg_key == &wxlua_lreg_debug_refs_key) { ! // For this table we push the value for a faster index ! lua_pushvalue(L, ABS_LUA_STKIDX(stack_idx,1)); // push key (the value) ! lua_rawget(L, -2); // get t[key] = value; pop key push value if (lua_isnumber(L, -1)) tag = (int)lua_tonumber(L, -1); ! lua_pop(L, 2); // pop object we pushed and the ref table } else { + // otherwise search through all the values lua_pushnil(L); ! while (lua_next(L, -2) != 0) { ! // value = -1, key = -2, table = -3, object = stack_idx before 3 added items ! if (lua_equal(L, -1, ABS_LUA_STKIDX(stack_idx,3))) { tag = (int)lua_tonumber(L, -2); *************** *** 500,504 **** } ! lua_pop(L, 2); // pop object we pushed and the ref table } --- 434,438 ---- } ! lua_pop(L, 1); // pop object we pushed and the ref table } *************** *** 520,524 **** const wxLuaBindClass* wxlClass = (wxLuaBindClass *)lua_touserdata(L, -1); // actually lightuserdata ! lua_pop(L, 2); // pop wxLuaReferences table and lightuserdata (or nil if none) return wxlClass; --- 454,458 ---- const wxLuaBindClass* wxlClass = (wxLuaBindClass *)lua_touserdata(L, -1); // actually lightuserdata ! lua_pop(L, 2); // pop tag table and lightuserdata (or nil if none) return wxlClass; *************** *** 530,541 **** const wxLuaBindClass* LUACALL wxluaT_getclass(lua_State* L, const char* class_name) { ! lua_pushlightuserdata(L, &wxlua_lreg_classes_key); ! lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push result (the classes table) ! lua_pushstring(L, class_name); // t["class_name"] = lightuserdata wxLuaBindClass (or nil if not a class tag) ! lua_rawget(L, -2); const wxLuaBindClass* wxlClass = (wxLuaBindClass *)lua_touserdata(L, -1); // actually lightuserdata ! lua_pop(L, 2); // pop wxLuaClasses table and lightuserdata (or nil if none) return wxlClass; --- 464,475 ---- const wxLuaBindClass* LUACALL wxluaT_getclass(lua_State* L, const char* class_name) { ! lua_pushlightuserdata(L, &wxlua_lreg_classes_key); // push key ! lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push value (table) ! lua_pushstring(L, class_name); // push key ! lua_rawget(L, -2); // get t["class_name"] = &wxLuaBindClass; pop key push value const wxLuaBindClass* wxlClass = (wxLuaBindClass *)lua_touserdata(L, -1); // actually lightuserdata ! lua_pop(L, 2); // pop table and lightuserdata (or nil if none) return wxlClass; *************** *** 544,547 **** --- 478,482 ---- int LUACALL wxlua_isderivedclass(lua_State* L, int class_tag, int base_class_tag) { + // These two class tags are the same if (class_tag == base_class_tag) return 0; *************** *** 551,555 **** int levels = 1; ! while (wxlClass != NULL) // check level by level { if (wxlClass->baseclass && (*wxlClass->baseclass->class_tag == base_class_tag)) --- 486,490 ---- int levels = 1; ! while (wxlClass != NULL) // check baseclass by baseclass { if (wxlClass->baseclass && (*wxlClass->baseclass->class_tag == base_class_tag)) *************** *** 560,568 **** } ! return -1; } int LUACALL wxlua_isderivedclass(const wxLuaBindClass* wxlClass, const wxLuaBindClass* wxlBaseClass) { if ((wxlClass == NULL) || (wxlBaseClass == NULL)) return -1; --- 495,504 ---- } ! return -1; // class_tag is not derived from base_class_tag } int LUACALL wxlua_isderivedclass(const wxLuaBindClass* wxlClass, const wxLuaBindClass* wxlBaseClass) { + // Ok if either is NULL to allow since we can blindly call this if ((wxlClass == NULL) || (wxlBaseClass == NULL)) return -1; *************** *** 579,583 **** } ! return -1; } --- 515,519 ---- } ! return -1; // wxlClass is not derived from wxlBaseClass } *************** *** 721,725 **** if (!wxlua_isstringtype(L, stack_idx)) { ! wxString msg(wxString::Format(_("wxLua: Expected a string for parameter %d, but got '%s'."), stack_idx, lua2wx(lua_typename(L, lua_type(L, stack_idx))).c_str())); wxlua_error(L, msg); --- 657,661 ---- if (!wxlua_isstringtype(L, stack_idx)) { ! wxString msg(wxString::Format(_("wxLua: Expected a string for parameter %d, but got a '%s'."), stack_idx, lua2wx(lua_typename(L, lua_type(L, stack_idx))).c_str())); wxlua_error(L, msg); *************** *** 734,738 **** if (!wxlua_iswxluatype(l_type, WXLUAARG_Boolean)) { ! wxString msg(wxString::Format(_("wxLua: Expected a boolean for parameter %d, but got '%s'."), stack_idx, lua2wx(lua_typename(L, lua_type(L, stack_idx))).c_str())); wxlua_error(L, msg); --- 670,674 ---- if (!wxlua_iswxluatype(l_type, WXLUAARG_Boolean)) { ! wxString msg(wxString::Format(_("wxLua: Expected a boolean for parameter %d, but got a '%s'."), stack_idx, lua2wx(lua_typename(L, lua_type(L, stack_idx))).c_str())); wxlua_error(L, msg); *************** *** 754,758 **** if (!wxlua_iswxluatype(l_type, WXLUAARG_Integer)) { ! wxString msg(wxString::Format(_("wxLua: Expected an integer for parameter %d, but got '%s'."), stack_idx, lua2wx(lua_typename(L, lua_type(L, stack_idx))).c_str())); wxlua_error(L, msg); --- 690,694 ---- if (!wxlua_iswxluatype(l_type, WXLUAARG_Integer)) { ! wxString msg(wxString::Format(_("wxLua: Expected an integer for parameter %d, but got a '%s'."), stack_idx, lua2wx(lua_typename(L, lua_type(L, stack_idx))).c_str())); wxlua_error(L, msg); *************** *** 781,785 **** if (!wxlua_iswxluatype(l_type, WXLUAARG_Number)) { ! wxString msg(wxString::Format(_("wxLua: Expected a number for parameter %d, but got '%s'."), stack_idx, lua2wx(lua_typename(L, lua_type(L, stack_idx))).c_str())); wxlua_error(L, msg); --- 717,721 ---- if (!wxlua_iswxluatype(l_type, WXLUAARG_Number)) { ! wxString msg(wxString::Format(_("wxLua: Expected a number for parameter %d, but got a '%s'."), stack_idx, lua2wx(lua_typename(L, lua_type(L, stack_idx))).c_str())); wxlua_error(L, msg); *************** *** 819,823 **** else { ! wxString msg(wxString::Format(_("wxLua: Expected a table of strings for parameter %d, but got '%s'."), stack_idx, lua2wx(lua_typename(L, lua_type(L, stack_idx))).c_str())); wxlua_error(L, msg); --- 755,759 ---- else { ! wxString msg(wxString::Format(_("wxLua: Expected a table of strings for parameter %d, but got a '%s'."), stack_idx, lua2wx(lua_typename(L, lua_type(L, stack_idx))).c_str())); wxlua_error(L, msg); *************** *** 859,869 **** bool LUACALL wxlua_setderivedmethod(lua_State* L, void *pObject, const char *method_name, wxLuaObject* wxlObj) { ! lua_pushlightuserdata(L, &wxlua_lreg_derivedmethods_key); ! lua_rawget( L, LUA_REGISTRYINDEX ); // pop key, push table if (lua_istable(L, -1)) // else not installed or already removed? Not good in any case. { ! lua_pushlightuserdata(L, (void *)pObject); ! lua_rawget(L, -2); // pop key, push table or nil if (!lua_istable(L, -1)) { --- 795,806 ---- bool LUACALL wxlua_setderivedmethod(lua_State* L, void *pObject, const char *method_name, wxLuaObject* wxlObj) { ! lua_pushlightuserdata(L, &wxlua_lreg_derivedmethods_key); // push key ! lua_rawget( L, LUA_REGISTRYINDEX ); // pop key, push value (table) if (lua_istable(L, -1)) // else not installed or already removed? Not good in any case. { ! lua_pushlightuserdata(L, (void *)pObject); // push key ! lua_rawget(L, -2); // get t[key] = value, pop key push value ! if (!lua_istable(L, -1)) { *************** *** 921,924 **** --- 858,862 ---- lua_pushlightuserdata(L, (void *)pObject); lua_rawget(L, -2); // pop key, push table or nil + if (lua_istable(L, -1)) { *************** *** 962,971 **** lua_pushlightuserdata(L, (void *)pObject); lua_rawget(L, -2); // pop key, push table or nil if (lua_istable(L, -1)) { found = true; ! int t = lua_gettop(L); lua_pushnil(L); /* first key */ ! while (lua_next(L, t) != 0) { // uses 'key' (at index -2) and 'value' (at index -1) --- 900,910 ---- lua_pushlightuserdata(L, (void *)pObject); lua_rawget(L, -2); // pop key, push table or nil + if (lua_istable(L, -1)) { found = true; ! lua_pushnil(L); /* first key */ ! while (lua_next(L, -2) != 0) { // uses 'key' (at index -2) and 'value' (at index -1) *************** *** 982,989 **** } ! lua_pop(L, 1); // pop the obj table ! lua_pushlightuserdata(L, (void *)pObject); ! lua_pushnil(L); ! lua_rawset(L, -3); // nil the obj table lua_pop(L, 1); // pop reg table } --- 921,930 ---- } ! lua_pop(L, 1); // pop the obj table so reg table is on top ! ! lua_pushlightuserdata(L, (void *)pObject); // push key ! lua_pushnil(L); // push value, to remove it ! lua_rawset(L, -3); // set t[key] = value; pop key and value ! lua_pop(L, 1); // pop reg table } *************** *** 1005,1010 **** lua_pushlightuserdata(L, &wxlua_lreg_callbaseclassfunc_key); 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; --- 946,952 ---- lua_pushlightuserdata(L, &wxlua_lreg_callbaseclassfunc_key); lua_rawget( L, LUA_REGISTRYINDEX ); // pop key, push bool ! ! bool call_base = (bool)lua_toboolean(L, -1); // nil == 0 too ! lua_pop(L, 1); // pop bool return call_base; *************** *** 1705,1709 **** lua_pushcfunction(L, wxlua_traceback); // push our traceback function - //lua_pushcfunction(L, wxlua_tracebackFunction); // push our traceback function lua_insert(L, base); // put it under chunk and args --- 1647,1650 ---- *************** *** 1788,1810 **** return true; case LUA_YIELD: ! msg = wxT("lua: Thread is suspended"); break; case LUA_ERRRUN: ! msg = wxT("lua: Error while running chunk"); break; case LUA_ERRSYNTAX: ! msg = wxT("lua: Syntax error during pre-compilation"); break; case LUA_ERRMEM: ! msg = wxT("lua: Memory allocation error"); break; case LUA_ERRERR: ! msg = wxT("lua: Generic error or an error occurred while running the error handler"); break; case LUA_ERRFILE: ! msg = wxT("lua: Error occurred while opening file"); break; default : ! msg = wxT("lua: Unknown error"); break; } --- 1729,1751 ---- return true; case LUA_YIELD: ! msg = wxT("Lua: Thread is suspended"); break; case LUA_ERRRUN: ! msg = wxT("Lua: Error while running chunk"); break; case LUA_ERRSYNTAX: ! msg = wxT("Lua: Syntax error during pre-compilation"); break; case LUA_ERRMEM: ! msg = wxT("Lua: Memory allocation error"); break; case LUA_ERRERR: ! msg = wxT("Lua: Generic error or an error occurred while running the error handler"); break; case LUA_ERRFILE: ! msg = wxT("Lua: Error occurred while opening file"); break; default : ! msg = wxT("Lua: Unknown error"); break; } |