From: John L. <jr...@us...> - 2007-11-30 23:00:45
|
Update of /cvsroot/wxlua/wxLua/modules/wxlua/src In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv22316/wxLua/modules/wxlua/src Modified Files: wxlbind.cpp wxlcallb.cpp wxlstate.cpp Log Message: - wxLuaStackDialog has better search for all columns, collapse and expand tables, and show metatables. It also now uses a virtual wxListCtrl so it's much faster. - Separated the "tags" for C++ classes from "refs" for objects we want a handle on in the Lua registry by putting them in separate tables. - Removed wxlua_pushkey_XXX #defines since we now have a few tables in the registry that we use and those methods were not useful anymore. The lightuserdata keys are now const char* strings with a descriptive name, however only the mem address is used as the table key. - wxluaT_newtag() now leaves the created table on the stack. - Removed wxluaT_newweaktag() and wxluaT_settagmethod() since they were not needed anymore. Index: wxlstate.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlstate.cpp,v retrieving revision 1.139 retrieving revision 1.140 diff -C2 -d -r1.139 -r1.140 *** wxlstate.cpp 28 Nov 2007 22:55:00 -0000 1.139 --- wxlstate.cpp 30 Nov 2007 23:00:07 -0000 1.140 *************** *** 23,35 **** #include "wx/tokenzr.h" ! int wxlua_lreg_references_key = WXLUA_LREG_REFERENCES; ! int wxlua_lreg_classes_key = WXLUA_LREG_CLASSES; ! int wxlua_lreg_derivedmethods_key = WXLUA_LREG_DERIVED_METHODS; ! int wxlua_lreg_wxluastate_key = WXLUA_LREG_WXLUASTATE; ! int wxlua_lreg_objects_key = WXLUA_LREG_OBJECTS; ! 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; wxLuaState wxNullLuaState(false); --- 23,37 ---- #include "wx/tokenzr.h" ! const char* wxlua_lreg_tags_key = "wxLua metatable class tags"; ! const char* wxlua_lreg_refs_key = "wxLua object references"; ! const char* wxlua_lreg_debug_refs_key = "wxLuaDebug references"; ! const char* wxlua_lreg_classes_key = "wxLuaBindClasses structs"; ! const char* wxlua_lreg_derivedmethods_key = "wxLua derived class methods"; ! const char* wxlua_lreg_wxluastate_key = "wxLuaState"; ! const char* wxlua_lreg_objects_key = "wxLua pushed userdata"; ! const char* wxlua_lreg_callbaseclassfunc_key = "wxLua CallBaseClassFunc"; ! const char* wxlua_metatable_tag_key = "wxLua Metatable Class Tag"; ! const char* wxlua_metatable_wxluabindclass_key = "wxLua Metatable wxLuaBindClass"; wxLuaState wxNullLuaState(false); *************** *** 243,247 **** // call ref 3 times and the new references will be 4, 3, 6 ! int wxluaT_insert(lua_State* L, int stack_idx) { if (lua_isnone(L, stack_idx)) // nothing on stack to insert --- 245,249 ---- // call ref 3 times and the new references will be 4, 3, 6 ! 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 *************** *** 254,259 **** } ! wxlua_pushkey_wxLuaReferences(L); // 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 --- 256,261 ---- } ! 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 *************** *** 262,265 **** --- 264,276 ---- // 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 *************** *** 267,291 **** } ! bool wxluaT_remove(lua_State* L, int wxlref_index) { if (wxlref_index == LUA_REFNIL) // nothing to remove return true; ! wxlua_pushkey_wxLuaReferences(L); // push name of table to get as key ! lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push result (the refs table) 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) { if (wxlref_index == LUA_REFNIL) // nothing to get return false; ! wxlua_pushkey_wxLuaReferences(L); // 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 --- 278,313 ---- } ! 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 *************** *** 312,316 **** if (tag != g_wxluatag_wxLuaFunction) { ! wxlua_pushkey_wxLuaObjects(L); lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push result (the obj table) lua_pushlightuserdata(L, (void*)u); // key on Lua's userdata --- 334,338 ---- if (tag != g_wxluatag_wxLuaFunction) { ! 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 *************** *** 333,337 **** *ptr = u; // try to get the object's references table and set the metatable to the object ! if (wxluaT_get(L, tag)) { // pop the table and set it as the metatable for the newuserdata --- 355,359 ---- *ptr = u; // try to get the object's references table and set the metatable to the object ! if (wxluaT_get(L, tag, &wxlua_lreg_tags_key)) { // pop the table and set it as the metatable for the newuserdata *************** *** 340,344 **** if (track) { ! wxlua_pushkey_wxLuaObjects(L); lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push result (the obj table) --- 362,366 ---- if (track) { ! lua_pushlightuserdata(L, &wxlua_lreg_objects_key); lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push result (the obj table) *************** *** 366,370 **** void LUACALL wxluaT_untrackuserdata(lua_State *L, const void *u) { ! wxlua_pushkey_wxLuaObjects(L); lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push result (the object table) lua_pushlightuserdata(L, (void*)u); --- 388,392 ---- 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); *************** *** 376,380 **** void LUACALL wxluaT_cleartrackedmetatable(lua_State *L, const void *u) { ! wxlua_pushkey_wxLuaObjects(L); lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push result (the object table) lua_pushlightuserdata(L, (void*)u); --- 398,402 ---- 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); *************** *** 395,399 **** if (lua_getmetatable(L, stack_idx) != 0) // see wxluaT_newtag { ! wxlua_pushkey_metatableTag(L); // 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 --- 417,421 ---- 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 *************** *** 422,477 **** int wxluaT_newtag(lua_State* L) { ! lua_newtable(L); // create a table for our new tag ! int tag = wxluaT_insert(L, -1); // insert the table into the wxLuaReferences registry table ! ! wxlua_pushkey_metatableTag(L); // add t[tag_key] = tag to new table ! lua_pushnumber(L, tag); ! lua_rawset(L, -3); ! ! lua_pop(L, 1); // pop our new table ! return tag; ! } ! ! int wxluaT_newweaktag(lua_State* L, bool weak_keys, bool weak_values) ! { ! //if (!weak_keys && !weak_values) return wxluaT_newtag(L); ! ! lua_newtable(L); // main table ! lua_newtable(L); // metatable ! ! lua_pushlstring(L, "__mode", 6); ! ! // for metatable.__weak = k for weak keys, v for weak values ! if (weak_keys) ! { ! if (weak_values) ! lua_pushlstring(L, "kv", 2); ! else ! lua_pushlstring(L, "k", 1); ! } ! else ! { ! if (weak_values) ! lua_pushlstring(L, "v", 1); ! else // yeah, we really shouldn't reach here ! lua_pushnil(L); ! } ! ! lua_rawset(L, -3); // set mode of main table ! lua_setmetatable(L, -2); // via the metatable ! ! int tag = wxluaT_insert(L, -1); // insert the table into the wxLuaReferences registry table ! wxlua_pushkey_metatableTag(L); // add t[tag_key] = tag to new table lua_pushnumber(L, tag); lua_rawset(L, -3); ! lua_pop(L, 1); // pop our new table ! return tag; } bool LUACALL wxluaT_settag(lua_State *L, int tag) { ! if (wxluaT_get(L, tag)) // 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 --- 444,460 ---- 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 } bool LUACALL wxluaT_settag(lua_State *L, int tag) { ! 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 *************** *** 484,537 **** } ! bool LUACALL wxluaT_settagmethod(lua_State *L, int tag, const char *method_name, ! lua_CFunction func, void *pClass /* = NULL*/) ! { ! if (wxluaT_get(L, tag)) // get the metatable for the object from the ! { // wxLuaReferences registy table ! if (pClass != NULL) ! { ! lua_pushstring(L, method_name); // push method name ! lua_pushlightuserdata(L, pClass); // push the userdata ! lua_pushcclosure(L, func, 1); // push func with pClass as upvalue ! } ! else ! { ! lua_pushstring(L, method_name); ! lua_pushcclosure(L, func, 0); ! } ! ! lua_rawset(L, -3); // t["method_name"] = closure of func (and upvalues) ! lua_pop(L, 1); // pop the table from wxluaT_get we got from the wxLuaReferences registry table ! return true; ! } ! ! return false; ! } ! ! int LUACALL wxluaT_isrefed(lua_State* L, int stack_idx) { int tag = LUA_NOREF; ! lua_pushvalue(L, stack_idx); // push value to compare ! ! wxlua_pushkey_wxLuaReferences(L); // push name of table to get as key lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push result (the refs table) - int nTop = lua_gettop(L); // this is where refs table is ! lua_pushnil(L); ! while (lua_next(L, nTop) != 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); ! lua_pop(L, 2); // pop key, value ! break; } - else - lua_pop(L, 1); // pop value, lua_next will pop key at end - } ! lua_pop(L, 2); // pop object we pushed and the ref table return tag; --- 467,505 ---- } ! int LUACALL wxluaT_isrefed(lua_State* L, int stack_idx, const void* lightuserdata_reg_key) { 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); ! lua_pop(L, 2); // pop key, value ! break; ! } ! else ! lua_pop(L, 1); // pop value, lua_next will pop key at end } ! lua_pop(L, 2); // pop object we pushed and the ref table ! } return tag; *************** *** 545,552 **** { // note: wxluaT_get doesn't leave anything on the stack on failure ! if (wxluaT_get(L, class_tag) && lua_istable(L, -1)) { // t[class_tag] = { [bindclass_key] = lightuserdata wxLuaBindClass... (or nil if not a class tag) ! wxlua_pushkey_metatableClass(L); lua_rawget(L, -2); const wxLuaBindClass* wxlClass = (wxLuaBindClass *)lua_touserdata(L, -1); // actually lightuserdata --- 513,520 ---- { // note: wxluaT_get doesn't leave anything on the stack on failure ! if (wxluaT_get(L, class_tag, &wxlua_lreg_tags_key) && lua_istable(L, -1)) { // t[class_tag] = { [bindclass_key] = lightuserdata wxLuaBindClass... (or nil if not a class tag) ! lua_pushlightuserdata(L, &wxlua_metatable_wxluabindclass_key); lua_rawget(L, -2); const wxLuaBindClass* wxlClass = (wxLuaBindClass *)lua_touserdata(L, -1); // actually lightuserdata *************** *** 562,566 **** const wxLuaBindClass* LUACALL wxluaT_getclass(lua_State* L, const char* class_name) { ! wxlua_pushkey_wxLuaClasses(L); lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push result (the classes table) --- 530,534 ---- 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) *************** *** 891,895 **** bool LUACALL wxlua_setderivedmethod(lua_State* L, void *pObject, const char *method_name, wxLuaObject* wxlObj) { ! wxlua_pushkey_wxLuaDerivedMethods(L); lua_rawget( L, LUA_REGISTRYINDEX ); // pop key, push table --- 859,863 ---- 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 *************** *** 944,948 **** bool found = false; ! wxlua_pushkey_wxLuaDerivedMethods(L); lua_rawget( L, LUA_REGISTRYINDEX ); // pop key, push table --- 912,916 ---- bool found = false; ! lua_pushlightuserdata(L, &wxlua_lreg_derivedmethods_key); lua_rawget( L, LUA_REGISTRYINDEX ); // pop key, push table *************** *** 987,991 **** bool found = false; ! wxlua_pushkey_wxLuaDerivedMethods(L); lua_rawget( L, LUA_REGISTRYINDEX ); // pop key, push table --- 955,959 ---- bool found = false; ! lua_pushlightuserdata(L, &wxlua_lreg_derivedmethods_key); lua_rawget( L, LUA_REGISTRYINDEX ); // pop key, push table *************** *** 1035,1039 **** 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); --- 1003,1007 ---- bool LUACALL wxlua_getcallbaseclassfunction(lua_State*L) { ! lua_pushlightuserdata(L, &wxlua_lreg_callbaseclassfunc_key); lua_rawget( L, LUA_REGISTRYINDEX ); // pop key, push bool bool call_base = (bool)lua_toboolean(L, -1); *************** *** 1045,1049 **** 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 --- 1013,1017 ---- void LUACALL wxlua_setcallbaseclassfunction(lua_State*L, bool call_base) { ! lua_pushlightuserdata(L, &wxlua_lreg_callbaseclassfunc_key); lua_pushboolean(L, call_base); lua_rawset( L, LUA_REGISTRYINDEX ); // pop key and bool *************** *** 1378,1394 **** } ! wxlua_pushkey_wxLuaState(m_lua_State); lua_pushnil(m_lua_State); lua_rawset(m_lua_State, LUA_REGISTRYINDEX); ! wxlua_pushkey_wxLuaReferences(m_lua_State); lua_pushnil(m_lua_State); lua_rawset(m_lua_State, LUA_REGISTRYINDEX); ! wxlua_pushkey_wxLuaClasses(m_lua_State); lua_pushnil(m_lua_State); lua_rawset(m_lua_State, LUA_REGISTRYINDEX); ! //wxlua_pushkey_wxLuaDerivedMethods(m_lua_State); // gc will delete them //lua_pushnil(m_lua_State); //lua_rawset(m_lua_State, LUA_REGISTRYINDEX); --- 1346,1370 ---- } ! lua_pushlightuserdata(m_lua_State, &wxlua_lreg_wxluastate_key); lua_pushnil(m_lua_State); lua_rawset(m_lua_State, LUA_REGISTRYINDEX); ! lua_pushlightuserdata(m_lua_State, &wxlua_lreg_tags_key); lua_pushnil(m_lua_State); lua_rawset(m_lua_State, LUA_REGISTRYINDEX); ! lua_pushlightuserdata(m_lua_State, &wxlua_lreg_refs_key); lua_pushnil(m_lua_State); lua_rawset(m_lua_State, LUA_REGISTRYINDEX); ! lua_pushlightuserdata(m_lua_State, &wxlua_lreg_debug_refs_key); ! lua_pushnil(m_lua_State); ! lua_rawset(m_lua_State, LUA_REGISTRYINDEX); ! ! lua_pushlightuserdata(m_lua_State, &wxlua_lreg_classes_key); ! lua_pushnil(m_lua_State); ! lua_rawset(m_lua_State, LUA_REGISTRYINDEX); ! ! //lua_pushlightuserdata(m_lua_State, &wxlua_lreg_derivedmethods_key); // gc will delete them //lua_pushnil(m_lua_State); //lua_rawset(m_lua_State, LUA_REGISTRYINDEX); *************** *** 1409,1413 **** // try to get the state we've stored ! wxlua_pushkey_wxLuaState(L); lua_rawget( L, LUA_REGISTRYINDEX ); --- 1385,1389 ---- // try to get the state we've stored ! lua_pushlightuserdata(L, &wxlua_lreg_wxluastate_key); lua_rawget( L, LUA_REGISTRYINDEX ); *************** *** 1514,1518 **** // Stick us into the Lua registry table - push key, value ! wxlua_pushkey_wxLuaState(L); lua_pushlightuserdata( L, (void*)hashState ); lua_rawset( L, LUA_REGISTRYINDEX ); // set the value --- 1490,1494 ---- // Stick us into the Lua registry table - push key, value ! lua_pushlightuserdata(L, &wxlua_lreg_wxluastate_key); lua_pushlightuserdata( L, (void*)hashState ); lua_rawset( L, LUA_REGISTRYINDEX ); // set the value *************** *** 1936,1951 **** lua_State* L = M_WXLSTATEDATA->m_lua_State; ! // create the wxLuaReferences table in registry ! wxlua_pushkey_wxLuaReferences(L); lua_newtable(L); lua_rawset(L, LUA_REGISTRYINDEX); // set the value // create the wxLuaClasses table in the registry ! wxlua_pushkey_wxLuaClasses(L); lua_newtable(L); lua_rawset(L, LUA_REGISTRYINDEX); // Create a table for overridden methods for C++ userdata objects ! wxlua_pushkey_wxLuaDerivedMethods(L); lua_newtable(L); lua_rawset( L, LUA_REGISTRYINDEX ); // set the value --- 1912,1937 ---- lua_State* L = M_WXLSTATEDATA->m_lua_State; ! // create the tags table in registry ! lua_pushlightuserdata(L, &wxlua_lreg_tags_key); ! lua_newtable(L); ! lua_rawset(L, LUA_REGISTRYINDEX); // set the value ! ! // create the refs table in registry ! lua_pushlightuserdata(L, &wxlua_lreg_refs_key); ! lua_newtable(L); ! lua_rawset(L, LUA_REGISTRYINDEX); // set the value ! ! // create the debug refs table in registry ! lua_pushlightuserdata(L, &wxlua_lreg_debug_refs_key); lua_newtable(L); lua_rawset(L, LUA_REGISTRYINDEX); // set the value // create the wxLuaClasses table in the registry ! lua_pushlightuserdata(L, &wxlua_lreg_classes_key); lua_newtable(L); lua_rawset(L, LUA_REGISTRYINDEX); // Create a table for overridden methods for C++ userdata objects ! lua_pushlightuserdata(L, &wxlua_lreg_derivedmethods_key); lua_newtable(L); lua_rawset( L, LUA_REGISTRYINDEX ); // set the value *************** *** 1953,1962 **** // Create a table for the userdata that we've pushed into Lua // Use weak values so the gc works on them ! wxlua_pushkey_wxLuaObjects(L); ! lua_newtable(L); // main table ! lua_newtable(L); // metatable ! lua_pushlstring(L, "__mode", 6); ! lua_pushlstring(L, "v", 1); ! lua_rawset(L, -3); // set mode of main table lua_setmetatable(L, -2); // via the metatable lua_rawset( L, LUA_REGISTRYINDEX ); // set the value --- 1939,1948 ---- // Create a table for the userdata that we've pushed into Lua // Use weak values so the gc works on them ! lua_pushlightuserdata(L, &wxlua_lreg_objects_key); ! lua_newtable(L); // main table ! lua_newtable(L); // metatable ! lua_pushlstring(L, "__mode", 6); ! lua_pushlstring(L, "v", 1); ! lua_rawset(L, -3); // set mode of main table lua_setmetatable(L, -2); // via the metatable lua_rawset( L, LUA_REGISTRYINDEX ); // set the value *************** *** 2056,2064 **** } ! // register our 'function' object handlers g_wxluatag_wxLuaFunction = wxluaT_NewTag(); ! wxluaT_SetTagMethod(g_wxluatag_wxLuaFunction, "__gc", wxlua__gc_wxLuaFunction); ! wxluaT_SetTagMethod(g_wxluatag_wxLuaFunction, "__call", wxlua__call_wxLuaFunction); // Finally - set the global tags from the bindings we've just installed --- 2042,2057 ---- } ! // Create a metatable for our C function wrapper wxLuaFunction g_wxluatag_wxLuaFunction = wxluaT_NewTag(); ! lua_pushstring(L, "__gc"); ! lua_pushcfunction(L, wxlua__gc_wxLuaFunction); ! lua_rawset(L, -3); // t["method_name"] = closure of func ! ! lua_pushstring(L, "__call"); ! lua_pushcfunction(L, wxlua__call_wxLuaFunction); ! lua_rawset(L, -3); // t["method_name"] = closure of func ! ! lua_pop(L, 1); // remove the new table from wxluaT_NewTag() // Finally - set the global tags from the bindings we've just installed *************** *** 2503,2522 **** // wxLua Lua Registry Table Functions ! int wxLuaState::wxluaT_Insert(int stack_idx) { wxCHECK_MSG(Ok(), LUA_REFNIL, wxT("Invalid wxLuaState")); ! return wxluaT_insert(M_WXLSTATEDATA->m_lua_State, stack_idx); } ! bool wxLuaState::wxluaT_Remove(int wxlref_index) { wxCHECK_MSG(Ok(), false, wxT("Invalid wxLuaState")); ! return wxluaT_remove(M_WXLSTATEDATA->m_lua_State, wxlref_index); } ! bool wxLuaState::wxluaT_Get(int wxlref_index) { wxCHECK_MSG(Ok(), false, wxT("Invalid wxLuaState")); ! return wxluaT_get(M_WXLSTATEDATA->m_lua_State, wxlref_index); } --- 2496,2515 ---- // wxLua Lua Registry Table Functions ! int wxLuaState::wxluaT_Insert(int stack_idx, const void* lightuserdata_reg_key) { wxCHECK_MSG(Ok(), LUA_REFNIL, wxT("Invalid wxLuaState")); ! return wxluaT_insert(M_WXLSTATEDATA->m_lua_State, stack_idx, lightuserdata_reg_key); } ! bool wxLuaState::wxluaT_Remove(int wxlref_index, const void* lightuserdata_reg_key) { wxCHECK_MSG(Ok(), false, wxT("Invalid wxLuaState")); ! return wxluaT_remove(M_WXLSTATEDATA->m_lua_State, wxlref_index, lightuserdata_reg_key); } ! bool wxLuaState::wxluaT_Get(int wxlref_index, const void* lightuserdata_reg_key) { wxCHECK_MSG(Ok(), false, wxT("Invalid wxLuaState")); ! return wxluaT_get(M_WXLSTATEDATA->m_lua_State, wxlref_index, lightuserdata_reg_key); } *************** *** 2551,2560 **** } - int wxLuaState::wxluaT_NewWeakTag(bool weak_keys, bool weak_values) - { - wxCHECK_MSG(Ok(), WXLUA_NOTAG, wxT("Invalid wxLuaState")); - return wxluaT_newweaktag(M_WXLSTATEDATA->m_lua_State, weak_keys, weak_values); - } - bool wxLuaState::wxluaT_SetTag(int tag) { --- 2544,2547 ---- *************** *** 2563,2572 **** } - bool wxLuaState::wxluaT_SetTagMethod(int tag, const char *method, lua_CFunction func, void *pClass /* = NULL*/) - { - wxCHECK_MSG(Ok(), false, wxT("Invalid wxLuaState")); - return wxluaT_settagmethod(M_WXLSTATEDATA->m_lua_State, tag, method, func, pClass); - } - // ---------------------------------------------------------------------------- // wxLua get data type --- 2550,2553 ---- Index: wxlbind.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlbind.cpp,v retrieving revision 1.95 retrieving revision 1.96 diff -C2 -d -r1.95 -r1.96 *** wxlbind.cpp 28 Nov 2007 00:20:49 -0000 1.95 --- wxlbind.cpp 30 Nov 2007 23:00:07 -0000 1.96 *************** *** 101,105 **** { // set up the reference to the item on the stack ! m_reference = m_wxlState->wxluaT_Insert(stack_idx); } --- 101,105 ---- { // set up the reference to the item on the stack ! m_reference = m_wxlState->wxluaT_Insert(stack_idx, &wxlua_lreg_refs_key); } *************** *** 113,117 **** // If a refererence exists, remove it, but don't bother if Lua is being closed if ((m_reference != LUA_NOREF) && m_wxlState->Ok() && !m_wxlState->IsClosing()) ! m_wxlState->wxluaT_Remove(m_reference); delete m_wxlState; --- 113,117 ---- // If a refererence exists, remove it, but don't bother if Lua is being closed if ((m_reference != LUA_NOREF) && m_wxlState->Ok() && !m_wxlState->IsClosing()) ! m_wxlState->wxluaT_Remove(m_reference, &wxlua_lreg_refs_key); delete m_wxlState; *************** *** 148,152 **** return true; } ! else if (m_wxlState->wxluaT_Get(m_reference)) return true; --- 148,152 ---- return true; } ! else if (m_wxlState->wxluaT_Get(m_reference, &wxlua_lreg_refs_key)) return true; *************** *** 159,165 **** if (m_reference != LUA_NOREF) // FIXME should this error out? ! m_wxlState->wxluaT_Remove(m_reference); ! m_reference = m_wxlState->wxluaT_Insert(stack_idx); } --- 159,165 ---- if (m_reference != LUA_NOREF) // FIXME should this error out? ! m_wxlState->wxluaT_Remove(m_reference, &wxlua_lreg_refs_key); ! m_reference = m_wxlState->wxluaT_Insert(stack_idx, &wxlua_lreg_refs_key); } *************** *** 308,312 **** { // name is NULL if it's not a string ! wxlua_error(L, wxString::Format(_("wxLua: Attempt to call a class method using '%s' on a '%s' type."), lua2wx(lua_typename(L, lua_type(L, 2))).c_str(), lua2wx(wxlClass ? wxlClass->name : "").c_str())); } --- 308,312 ---- { // name is NULL if it's not a string ! wxlua_error(L, wxString::Format(_("wxLua: Attempt to call a class method using '%s' on a '%s' type."), lua2wx(lua_typename(L, lua_type(L, 2))).c_str(), lua2wx(wxlClass ? wxlClass->name : "").c_str())); } *************** *** 388,392 **** if (!found) { ! wxlua_error(L, wxString::Format(_("wxLua: Attempt to call an unknown method '%s' on a '%s' type."), lua2wx(name).c_str(), lua2wx(wxlClass ? wxlClass->name : "").c_str())); } --- 388,392 ---- if (!found) { ! wxlua_error(L, wxString::Format(_("wxLua: Attempt to call an unknown method '%s' on a '%s' type."), lua2wx(name).c_str(), lua2wx(wxlClass ? wxlClass->name : "").c_str())); } *************** *** 576,580 **** m_start_tag(0), m_last_tag(0), ! m_luaTable_tag(-1) { } --- 576,580 ---- m_start_tag(0), m_last_tag(0), ! m_luaTable_ref(-1) { } *************** *** 656,660 **** // Find a registered binding with the same namespace, if any, ! // and share the m_luaTable_tag to that of the previously loaded binding wxLuaBindingList::compatibility_iterator node = wxlState.GetLuaBindingList()->GetFirst(); for (; node; node = node->GetNext()) --- 656,660 ---- // Find a registered binding with the same namespace, if any, ! // and share the m_luaTable_ref to that of the previously loaded binding wxLuaBindingList::compatibility_iterator node = wxlState.GetLuaBindingList()->GetFirst(); for (; node; node = node->GetNext()) *************** *** 662,668 **** wxLuaBinding* binding = node->GetData(); ! if ((binding->GetLuaNamespace() == m_nameSpace) && (binding->m_luaTable_tag >= 0)) { ! m_luaTable_tag = binding->m_luaTable_tag; break; } --- 662,668 ---- wxLuaBinding* binding = node->GetData(); ! if ((binding->GetLuaNamespace() == m_nameSpace) && (binding->m_luaTable_ref >= 0)) { ! m_luaTable_ref = binding->m_luaTable_ref; break; } *************** *** 670,680 **** // first time adding this namespace table ! if (m_luaTable_tag < 1) { ! // create a tag for the wxLua table ! m_luaTable_tag = wxlState.wxluaT_NewTag(); ! ! // set the table tag ! wxlState.wxluaT_SetTag(m_luaTable_tag); } --- 670,677 ---- // first time adding this namespace table ! if (m_luaTable_ref < 1) { ! // create a ref for the wxLua table we're filling ! m_luaTable_ref = wxlState.wxluaT_Insert(-1, &wxlua_lreg_refs_key); } *************** *** 715,720 **** lua_State *L = wxlState.GetLuaState(); - m_start_tag = wxlState.wxluaT_NewTag(); - int iTag = m_start_tag; --- 712,715 ---- *************** *** 726,730 **** // ------------------------------------------------------------------ // Add to the lookup table for "class name" to wxLuaBindClass struct ! wxlua_pushkey_wxLuaClasses(L); lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push result (the classes table) lua_pushstring(L, wxlClass->name); --- 721,725 ---- // ------------------------------------------------------------------ // Add to the lookup table for "class name" to wxLuaBindClass struct ! lua_pushlightuserdata(L, &wxlua_lreg_classes_key); lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push result (the classes table) lua_pushstring(L, wxlClass->name); *************** *** 737,744 **** iTag = wxlState.wxluaT_NewTag(); *wxlClass->class_tag = iTag; ! // store a lookup in the class metatable to the wxLuaBindClass struct ! wxluaT_get(L, iTag); ! wxlua_pushkey_metatableClass(L); lua_pushlightuserdata(L, (void *)wxlClass); lua_rawset(L, -3); // t[name] = tag --- 732,741 ---- iTag = wxlState.wxluaT_NewTag(); *wxlClass->class_tag = iTag; ! ! if (i_class == 0) ! m_start_tag = iTag; ! // store a lookup in the class metatable to the wxLuaBindClass struct ! lua_pushlightuserdata(L, &wxlua_metatable_wxluabindclass_key); lua_pushlightuserdata(L, (void *)wxlClass); lua_rawset(L, -3); // t[name] = tag *************** *** 747,752 **** for (size_t i_func = 0; i_func < s_funcCount; ++i_func) { - //wxlState.wxluaT_SetTagMethod(iTag, s_funcTable[i_func].name, s_funcTable[i_func].func, (void *)wxlClass); - lua_pushstring(L, s_funcTable[i_func].name); // push method name lua_pushlightuserdata(L, (void *)wxlClass); // push the userdata --- 744,747 ---- Index: wxlcallb.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlcallb.cpp,v retrieving revision 1.42 retrieving revision 1.43 diff -C2 -d -r1.42 -r1.43 *** wxlcallb.cpp 17 Nov 2007 00:15:02 -0000 1.42 --- wxlcallb.cpp 30 Nov 2007 23:00:07 -0000 1.43 *************** *** 52,56 **** // create a reference to the Lua event handler function if (lua_func_stack_idx != WXLUACALLBACK_NOROUTINE) ! m_routine = m_wxlState.wxluaT_Insert(lua_func_stack_idx); m_evtHandler->Connect(win_id, last_id, eventType, --- 52,56 ---- // create a reference to the Lua event handler function if (lua_func_stack_idx != WXLUACALLBACK_NOROUTINE) ! m_routine = m_wxlState.wxluaT_Insert(lua_func_stack_idx, &wxlua_lreg_refs_key); m_evtHandler->Connect(win_id, last_id, eventType, *************** *** 64,68 **** if (m_wxlState.Ok()) { ! m_wxlState.wxluaT_Remove(m_routine); // delete the reference to this handler m_wxlState.RemoveTrackedCallback(this); --- 64,68 ---- if (m_wxlState.Ok()) { ! m_wxlState.wxluaT_Remove(m_routine, &wxlua_lreg_refs_key); // delete the reference to this handler m_wxlState.RemoveTrackedCallback(this); *************** *** 131,135 **** wxlState.lua_CheckStack(LUA_MINSTACK); int oldTop = wxlState.lua_GetTop(); ! if (wxlState.wxluaT_Get(m_routine)) { wxlState.lua_PushValue(LUA_GLOBALSINDEX); --- 131,135 ---- wxlState.lua_CheckStack(LUA_MINSTACK); int oldTop = wxlState.lua_GetTop(); ! if (wxlState.wxluaT_Get(m_routine, &wxlua_lreg_refs_key)) { wxlState.lua_PushValue(LUA_GLOBALSINDEX); *************** *** 227,231 **** // remove the ref to the routine since we're clearing the wxLuaState // See ~wxLuaCallback ! m_wxlState.wxluaT_Remove(wxlCallback->GetLuaRoutine()); wxlCallback->ClearwxLuaState(); } --- 227,231 ---- // remove the ref to the routine since we're clearing the wxLuaState // See ~wxLuaCallback ! m_wxlState.wxluaT_Remove(wxlCallback->GetLuaRoutine(), &wxlua_lreg_refs_key); wxlCallback->ClearwxLuaState(); } |