From: John L. <jr...@us...> - 2007-12-04 05:20:33
|
Update of /cvsroot/wxlua/wxLua/modules/wxlua/src In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv16657/wxLua/modules/wxlua/src Modified Files: wxlbind.cpp wxlcallb.cpp wxlstate.cpp wxlua_bind.cpp Log Message: After separating the tags, refs, and debug refs in the Lua registry rename the wxluaT_XXX functions to match what they operate on wxluaR_ for generic ref functions wxluaT_ for tag functions wxluaO_ for object functions Index: wxlstate.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlstate.cpp,v retrieving revision 1.141 retrieving revision 1.142 diff -C2 -d -r1.141 -r1.142 *** wxlstate.cpp 3 Dec 2007 23:47:24 -0000 1.141 --- wxlstate.cpp 4 Dec 2007 05:20:28 -0000 1.142 *************** *** 43,48 **** // ---------------------------------------------------------------------------- ! // 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 ) --- 43,48 ---- // ---------------------------------------------------------------------------- ! // 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 ) *************** *** 178,185 **** // 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) { // nothing on stack to insert and don't bother inserting nil ! if (lua_isnoneornil(L, stack_idx)) return LUA_REFNIL; --- 178,185 ---- // call ref 3 times and the new references will be 4, 3, 6 ! int wxluaR_ref(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; *************** *** 195,199 **** { 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 } --- 195,199 ---- { 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 } *************** *** 204,208 **** } ! bool wxluaT_remove(lua_State* L, int table_idx, const void* lightuserdata_reg_key) { if (table_idx == LUA_REFNIL) // nothing to remove --- 204,208 ---- } ! bool wxluaR_unref(lua_State* L, int table_idx, const void* lightuserdata_reg_key) { if (table_idx == LUA_REFNIL) // nothing to remove *************** *** 216,220 **** { lua_pushnumber(L, table_idx); // push key ! lua_rawget(L, -2); // get t[key] = value; pop key, push value; lua_pushnil(L); --- 216,220 ---- { lua_pushnumber(L, table_idx); // push key ! lua_rawget(L, -2); // get t[key] = value; pop key, push value; lua_pushnil(L); *************** *** 223,227 **** 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 --- 223,227 ---- luaL_unref(L, -1, table_idx); // remove key and value in refs table ! // note: this key will be used for the next wxluaR_ref lua_pop(L, 1); // pop table *************** *** 230,234 **** } ! bool LUACALL wxluaT_get(lua_State *L, int table_idx, const void* lightuserdata_reg_key) { if (table_idx == LUA_REFNIL) // nothing to get --- 230,234 ---- } ! bool LUACALL wxluaR_getref(lua_State *L, int table_idx, const void* lightuserdata_reg_key) { if (table_idx == LUA_REFNIL) // nothing to get *************** *** 251,254 **** --- 251,338 ---- } + int LUACALL wxluaR_isrefed(lua_State* L, int stack_idx, const void* lightuserdata_reg_key) + { + 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); + 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, 1); // pop object we pushed and the ref table + } + + return tag; + } + + int wxluaT_newtag(lua_State* L) + { + lua_newtable(L); // create a table for our new tag + int tag = wxluaR_ref(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 + } + + int LUACALL wxluaT_gettag(lua_State *L, int stack_idx) + { + 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); + + lua_pop(L, 2); // pop metatable and tag number + } + + return tag; + } + + bool LUACALL wxluaT_settag(lua_State *L, int tag) + { + if (wxluaR_getref(L, tag, &wxlua_lreg_tags_key)) // get the metatable + { + 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."); + } + + return false; + } + bool LUACALL wxluaT_pushusertag(lua_State *L, const void *u, int tag, bool track) { *************** *** 262,267 **** if (tag != g_wxluatag_wxLuaFunction) { ! 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 --- 346,352 ---- if (tag != g_wxluatag_wxLuaFunction) { ! 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); // push key lua_rawget(L, -2); // get t[key] value; pop key push value *************** *** 272,276 **** return true; } ! lua_pop(L, 2); // pop the table and the nil. } --- 357,361 ---- return true; } ! lua_pop(L, 2); // pop the table and the nil. } *************** *** 282,286 **** *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 --- 367,371 ---- *ptr = u; // try to get the object's references table and set the metatable to the object ! if (wxluaR_getref(L, tag, &wxlua_lreg_tags_key)) { // pop the table and set it as the metatable for the newuserdata *************** *** 313,317 **** } ! void LUACALL wxluaT_untrackuserdata(lua_State *L, const void *u) { lua_pushlightuserdata(L, &wxlua_lreg_objects_key); // push key --- 398,402 ---- } ! void LUACALL wxluaO_untrackuserdata(lua_State *L, const void *u) { lua_pushlightuserdata(L, &wxlua_lreg_objects_key); // push key *************** *** 320,328 **** 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 --- 405,413 ---- lua_pushlightuserdata(L, (void*)u); // push key lua_pushnil(L); // push value ! lua_rawset(L, -3); // set t[key] = nil; pops key and value lua_pop(L, 1); // pop objects table } ! void LUACALL wxluaO_cleartrackedmetatable(lua_State *L, const void *u) { lua_pushlightuserdata(L, &wxlua_lreg_objects_key); // push key *************** *** 341,362 **** } - int LUACALL wxluaT_tag(lua_State *L, int stack_idx) - { - 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); - - lua_pop(L, 2); // pop metatable and tag number - } - - return tag; - } - void* LUACALL wxlua_touserdata(lua_State *L, int stack_idx, bool null_ptr /* = false*/) { --- 426,429 ---- *************** *** 374,443 **** } - 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 - } - - 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 - return true; - else - wxlua_error(L, "wxLua: Unable to set metatable in wxluaT_settag."); - } - - return false; - } - - 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 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); - 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, 1); // pop object we pushed and the ref table - } - - return tag; - } - // ---------------------------------------------------------------------------- // Functions to get info about the tags wxlua uses to determine type --- 441,444 ---- *************** *** 446,451 **** const wxLuaBindClass* LUACALL wxluaT_getclass(lua_State* L, int class_tag) { ! // 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) --- 447,452 ---- const wxLuaBindClass* LUACALL wxluaT_getclass(lua_State* L, int class_tag) { ! // note: wxluaR_getref() doesn't leave anything on the stack on failure ! if (wxluaR_getref(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) *************** *** 468,472 **** 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 --- 469,473 ---- 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 *************** *** 798,820 **** 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)) ! { ! lua_pop(L, 1); // pop nil value ! // add new table for this object ! lua_pushlightuserdata(L, (void *)pObject); ! lua_newtable(L); ! lua_rawset(L, -3); ! // put the new table back on the top of the stack ! lua_pushlightuserdata(L, (void *)pObject); ! lua_rawget(L, -2); ! } // see if there already is a method lua_pushstring( L, method_name ); --- 799,820 ---- lua_rawget( L, LUA_REGISTRYINDEX ); // pop key, push value (table) ! lua_pushlightuserdata(L, (void *)pObject); // push key ! lua_rawget(L, -2); // get t[key] = value, pop key push value ! if (!lua_istable(L, -1)) ! { ! lua_pop(L, 1); // pop nil value ! // add new table for this object ! lua_pushlightuserdata(L, (void *)pObject); // push key ! lua_newtable(L); // push value ! lua_rawset(L, -3); // set t[key] = value; pops key and value + // put the new table back on the top of the stack + lua_pushlightuserdata(L, (void *)pObject); + lua_rawget(L, -2); + } + else + { // see if there already is a method lua_pushstring( L, method_name ); *************** *** 829,845 **** lua_pop(L, 1); // pop the deleted old object, or nil ! lua_pushstring( L, method_name ); ! lua_pushlightuserdata(L, (void*)wxlObj); ! lua_rawset(L, -3); ! lua_pop(L, 2); // pop the object and overridden function table ! } ! else ! { ! lua_pop(L, 1); // pop the nil reg table ! wxlua_error(L, "wxLua: The wxLuaDerivedMethods table in the registry is missing!"); ! return false; ! } return true; --- 829,839 ---- lua_pop(L, 1); // pop the deleted old object, or nil + } ! lua_pushstring( L, method_name ); // push key ! lua_pushlightuserdata(L, (void*)wxlObj); // push value ! lua_rawset(L, -3); // set t[key] = value; pops key and value ! lua_pop(L, 2); // pop the object and overridden function table return true; *************** *** 848,888 **** { bool found = false; 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. ! { ! wxLuaObject* wxlObj = NULL; ! ! lua_pushlightuserdata(L, (void *)pObject); ! lua_rawget(L, -2); // pop key, push table or nil ! if (lua_istable(L, -1)) ! { ! // see if there is a method with the same name ! lua_pushstring( L, method_name ); ! lua_rawget(L, -2); ! if (lua_islightuserdata(L, -1)) ! wxlObj = (wxLuaObject*)lua_touserdata( L, -1 ); ! lua_pop(L, 1); // pop the method object or nil ! } ! lua_pop(L, 2); // pop registry table and object table or nil ! if (wxlObj != NULL) ! { ! if (push_method && wxlObj->GetObject()) ! found = true; ! else if (!push_method) ! found = true; ! } ! } ! else { ! lua_pop(L, 1); // pop the nil reg table ! wxlua_error(L, "wxLua: The wxLuaDerivedMethods table in the registry is missing!"); } --- 842,874 ---- { bool found = false; + wxLuaObject* wxlObj = NULL; lua_pushlightuserdata(L, &wxlua_lreg_derivedmethods_key); lua_rawget( L, LUA_REGISTRYINDEX ); // pop key, push table ! lua_pushlightuserdata(L, (void *)pObject); ! lua_rawget(L, -2); // pop key, push table or nil ! if (lua_istable(L, -1)) ! { ! // see if there is a method with the same name ! lua_pushstring( L, method_name ); ! lua_rawget(L, -2); ! if (lua_islightuserdata(L, -1)) ! wxlObj = (wxLuaObject*)lua_touserdata( L, -1 ); ! lua_pop(L, 1); // pop the method object or nil ! } ! lua_pop(L, 2); // pop registry table and object table or nil ! if (wxlObj != NULL) { ! // if we've got the object, put it on top of the stack ! if (push_method && wxlObj->GetObject()) ! found = true; ! else if (!push_method) ! found = true; } *************** *** 896,941 **** 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)) { ! found = true; ! lua_pushnil(L); /* first key */ ! while (lua_next(L, -2) != 0) { ! // uses 'key' (at index -2) and 'value' (at index -1) ! //wxPrintf(wxT("%s - %s\n"), lua2wx(lua_tostring(L, -2)).c_str(), lua2wx(lua_typename(L, lua_type(L, -1))).c_str()); ! ! if (lua_islightuserdata(L, -1)) ! { ! wxLuaObject* o = (wxLuaObject*)lua_touserdata(L, -1); ! delete o; ! } ! ! // removes 'value'; keeps 'key' for next iteration ! lua_pop(L, 1); } ! 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 ! } ! else ! lua_pop(L, 2); // pop the reg table and nil for the obj table } else ! { ! lua_pop(L, 1); // pop the nil reg table ! wxlua_error(L, "wxLua: The wxLuaDerivedMethods table in the registry is missing!"); ! return false; ! } return found; --- 882,917 ---- lua_rawget( L, LUA_REGISTRYINDEX ); // pop key, push table ! lua_pushlightuserdata(L, (void *)pObject); ! lua_rawget(L, -2); // pop key, push table or nil ! ! if (lua_istable(L, -1)) { ! found = true; ! // delete all of the derived methods we've pushed ! lua_pushnil(L); /* first key */ ! while (lua_next(L, -2) != 0) { ! // uses 'key' (at index -2) and 'value' (at index -1) ! if (lua_islightuserdata(L, -1)) { ! wxLuaObject* o = (wxLuaObject*)lua_touserdata(L, -1); ! delete o; } ! lua_pop(L, 1); // remove value; keep key for next iteration ! } ! 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 } else ! lua_pop(L, 2); // pop the reg table and nil for the obj table return found; *************** *** 2155,2159 **** // Nor are we tracking it within the Lua reg table if (WXLUA_HASBIT(flags, CLEAR_TRACKED_OBJECT)) ! wxluaT_untrackuserdata(L, pObject); wxLongToLongHashMap::iterator it = M_WXLSTATEDATA->m_wxlStateData->m_trackedObjects.find((long) pObject); --- 2131,2135 ---- // Nor are we tracking it within the Lua reg table if (WXLUA_HASBIT(flags, CLEAR_TRACKED_OBJECT)) ! wxluaO_untrackuserdata(L, pObject); wxLongToLongHashMap::iterator it = M_WXLSTATEDATA->m_wxlStateData->m_trackedObjects.find((long) pObject); *************** *** 2437,2456 **** // 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); } --- 2413,2432 ---- // wxLua Lua Registry Table Functions ! int wxLuaState::wxluaR_Ref(int stack_idx, const void* lightuserdata_reg_key) { wxCHECK_MSG(Ok(), LUA_REFNIL, wxT("Invalid wxLuaState")); ! return wxluaR_ref(M_WXLSTATEDATA->m_lua_State, stack_idx, lightuserdata_reg_key); } ! bool wxLuaState::wxluaR_Unref(int wxlref_index, const void* lightuserdata_reg_key) { wxCHECK_MSG(Ok(), false, wxT("Invalid wxLuaState")); ! return wxluaR_unref(M_WXLSTATEDATA->m_lua_State, wxlref_index, lightuserdata_reg_key); } ! bool wxLuaState::wxluaR_GetRef(int wxlref_index, const void* lightuserdata_reg_key) { wxCHECK_MSG(Ok(), false, wxT("Invalid wxLuaState")); ! return wxluaR_getref(M_WXLSTATEDATA->m_lua_State, wxlref_index, lightuserdata_reg_key); } *************** *** 2467,2474 **** } ! int wxLuaState::wxluaT_Tag(int stack_idx) const { wxCHECK_MSG(Ok(), WXLUA_NOTAG, wxT("Invalid wxLuaState")); ! return wxluaT_tag(M_WXLSTATEDATA->m_lua_State, stack_idx); } --- 2443,2450 ---- } ! int wxLuaState::wxluaT_GetTag(int stack_idx) const { wxCHECK_MSG(Ok(), WXLUA_NOTAG, wxT("Invalid wxLuaState")); ! return wxluaT_gettag(M_WXLSTATEDATA->m_lua_State, stack_idx); } *************** *** 2529,2533 **** if (wxlua_iswxuserdata(L, stack_idx)) { ! int stack_tag = wxluaT_tag(L, stack_idx); if ((g_wxluatag_NULL == stack_tag) || // FIXME, how to check when NULL is valid or not? (g_wxluatag_wxLuaFunction == stack_tag) || --- 2505,2509 ---- if (wxlua_iswxuserdata(L, stack_idx)) { ! int stack_tag = wxluaT_gettag(L, stack_idx); if ((g_wxluatag_NULL == stack_tag) || // FIXME, how to check when NULL is valid or not? (g_wxluatag_wxLuaFunction == stack_tag) || *************** *** 2547,2551 **** if (wxlua_iswxuserdata(L, stack_idx)) { ! int stack_tag = wxluaT_tag(L, stack_idx); if (g_wxluatag_wxLuaFunction == stack_tag) --- 2523,2527 ---- if (wxlua_iswxuserdata(L, stack_idx)) { ! int stack_tag = wxluaT_gettag(L, stack_idx); if (g_wxluatag_wxLuaFunction == stack_tag) *************** *** 2632,2636 **** else if (wxlua_iswxuserdata(L, stack_idx)) { ! int stack_tag = wxluaT_tag(L, stack_idx); if (wxlua_isderivedclass(L, stack_tag, g_wxluatag_wxString) >= 0) --- 2608,2612 ---- else if (wxlua_iswxuserdata(L, stack_idx)) { ! int stack_tag = wxluaT_gettag(L, stack_idx); if (wxlua_isderivedclass(L, stack_tag, g_wxluatag_wxString) >= 0) *************** *** 2672,2676 **** else if (wxlua_iswxuserdata(L, stack_idx)) { ! int stack_tag = wxluaT_tag(L, stack_idx); return (wxlua_isderivedclass(L, stack_tag, g_wxluatag_wxString) >= 0); } --- 2648,2652 ---- else if (wxlua_iswxuserdata(L, stack_idx)) { ! int stack_tag = wxluaT_gettag(L, stack_idx); return (wxlua_isderivedclass(L, stack_tag, g_wxluatag_wxString) >= 0); } *************** *** 2750,2754 **** else if (wxlua_iswxuserdata(L, stack_idx)) { ! int class_tag = wxluaT_tag(L, stack_idx); const wxLuaBindClass* wxlClass = wxluaT_getclass(L, class_tag); const wxLuaBindClass* arrStrClass = wxluaT_getclass(L, "wxArrayString"); --- 2726,2730 ---- else if (wxlua_iswxuserdata(L, stack_idx)) { ! int class_tag = wxluaT_gettag(L, stack_idx); const wxLuaBindClass* wxlClass = wxluaT_getclass(L, class_tag); const wxLuaBindClass* arrStrClass = wxluaT_getclass(L, "wxArrayString"); *************** *** 2850,2854 **** else if (wxlua_iswxuserdata(L, stack_idx)) { ! int class_tag = wxluaT_tag(L, stack_idx); const wxLuaBindClass* wxlClass = wxluaT_getclass(L, class_tag); const wxLuaBindClass* arrIntClass = wxluaT_getclass(L, "wxArrayInt"); --- 2826,2830 ---- else if (wxlua_iswxuserdata(L, stack_idx)) { ! int class_tag = wxluaT_gettag(L, stack_idx); const wxLuaBindClass* wxlClass = wxluaT_getclass(L, class_tag); const wxLuaBindClass* arrIntClass = wxluaT_getclass(L, "wxArrayInt"); *************** *** 3845,3849 **** else { ! int tag = wxluaT_Tag(arg+1+lua_argStart); fnCall += GetLuaTagName(tag); } --- 3821,3825 ---- else { ! int tag = wxluaT_GetTag(arg+1+lua_argStart); fnCall += GetLuaTagName(tag); } Index: wxlbind.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlbind.cpp,v retrieving revision 1.96 retrieving revision 1.97 diff -C2 -d -r1.96 -r1.97 *** wxlbind.cpp 30 Nov 2007 23:00:07 -0000 1.96 --- wxlbind.cpp 4 Dec 2007 05:20:28 -0000 1.97 *************** *** 69,73 **** { // Sanity check, but this is only attached to a wxLuaFunction, so it has to be ok. ! //if (wxlua_iswxuserdata(L, 1) && (wxluaT_tag(L, 1) == g_wxluatag_wxLuaFunction)) { wxLuaFunction *wxlFunction = (wxLuaFunction *)wxlua_touserdata(L, 1, true); --- 69,73 ---- { // Sanity check, but this is only attached to a wxLuaFunction, so it has to be ok. ! //if (wxlua_iswxuserdata(L, 1) && (wxluaT_gettag(L, 1) == g_wxluatag_wxLuaFunction)) { wxLuaFunction *wxlFunction = (wxLuaFunction *)wxlua_touserdata(L, 1, true); *************** *** 81,85 **** { // Sanity check, but this is only attached to a wxLuaFunction, so it has to be ok. ! //if (wxlua_iswxuserdata(L, 1) && (wxluaT_tag(L, 1) == g_wxluatag_wxLuaFunction)) { wxLuaFunction *f = (wxLuaFunction *)wxlua_touserdata(L, 1, false); --- 81,85 ---- { // Sanity check, but this is only attached to a wxLuaFunction, so it has to be ok. ! //if (wxlua_iswxuserdata(L, 1) && (wxluaT_gettag(L, 1) == g_wxluatag_wxLuaFunction)) { wxLuaFunction *f = (wxLuaFunction *)wxlua_touserdata(L, 1, false); *************** *** 101,105 **** { // set up the reference to the item on the stack ! m_reference = m_wxlState->wxluaT_Insert(stack_idx, &wxlua_lreg_refs_key); } --- 101,105 ---- { // set up the reference to the item on the stack ! m_reference = m_wxlState->wxluaR_Ref(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, &wxlua_lreg_refs_key); 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->wxluaR_Unref(m_reference, &wxlua_lreg_refs_key); delete m_wxlState; *************** *** 148,152 **** return true; } ! else if (m_wxlState->wxluaT_Get(m_reference, &wxlua_lreg_refs_key)) return true; --- 148,152 ---- return true; } ! else if (m_wxlState->wxluaR_GetRef(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, &wxlua_lreg_refs_key); ! m_reference = m_wxlState->wxluaT_Insert(stack_idx, &wxlua_lreg_refs_key); } --- 159,165 ---- if (m_reference != LUA_NOREF) // FIXME should this error out? ! m_wxlState->wxluaR_Unref(m_reference, &wxlua_lreg_refs_key); ! m_reference = m_wxlState->wxluaR_Ref(stack_idx, &wxlua_lreg_refs_key); } *************** *** 243,247 **** wxLuaBindClass *wxlClass = (wxLuaBindClass *)lua_touserdata(L, lua_upvalueindex(1)); ! if ((wxlClass != NULL) && wxlua_iswxuserdata(L, 1) && (wxluaT_tag(L, 1) == *wxlClass->class_tag)) { wxLuaState wxlState(L); --- 243,247 ---- wxLuaBindClass *wxlClass = (wxLuaBindClass *)lua_touserdata(L, lua_upvalueindex(1)); ! if ((wxlClass != NULL) && wxlua_iswxuserdata(L, 1) && (wxluaT_gettag(L, 1) == *wxlClass->class_tag)) { wxLuaState wxlState(L); *************** *** 311,315 **** lua2wx(lua_typename(L, lua_type(L, 2))).c_str(), lua2wx(wxlClass ? wxlClass->name : "").c_str())); } ! else if ((wxlClass != NULL) && wxlua_iswxuserdata(L, 1) && (wxluaT_tag(L, 1) == *wxlClass->class_tag)) { void *pObject = wxlua_touserdata(L, 1, false); --- 311,315 ---- lua2wx(lua_typename(L, lua_type(L, 2))).c_str(), lua2wx(wxlClass ? wxlClass->name : "").c_str())); } ! else if ((wxlClass != NULL) && wxlua_iswxuserdata(L, 1) && (wxluaT_gettag(L, 1) == *wxlClass->class_tag)) { void *pObject = wxlua_touserdata(L, 1, false); *************** *** 409,413 **** bool found = false; ! if ((wxlClass != NULL) && wxlua_iswxuserdata(L, 1) && (wxluaT_tag(L, 1) == *wxlClass->class_tag)) { // See if there is a WXLUAMETHOD_SETPROP in the wxLuaBindClass's wxLuaBindMethods --- 409,413 ---- bool found = false; ! if ((wxlClass != NULL) && wxlua_iswxuserdata(L, 1) && (wxluaT_gettag(L, 1) == *wxlClass->class_tag)) { // See if there is a WXLUAMETHOD_SETPROP in the wxLuaBindClass's wxLuaBindMethods *************** *** 465,469 **** str = wxString::Format(wxT("userdata: %p"), lua_touserdata(L, 1)); ! int nTag = wxluaT_tag(L, 1); if (nTag != WXLUA_NOTAG) { --- 465,469 ---- str = wxString::Format(wxT("userdata: %p"), lua_touserdata(L, 1)); ! int nTag = wxluaT_gettag(L, 1); if (nTag != WXLUA_NOTAG) { *************** *** 673,677 **** { // create a ref for the wxLua table we're filling ! m_luaTable_ref = wxlState.wxluaT_Insert(-1, &wxlua_lreg_refs_key); } --- 673,677 ---- { // create a ref for the wxLua table we're filling ! m_luaTable_ref = wxlState.wxluaR_Ref(-1, &wxlua_lreg_refs_key); } *************** *** 750,754 **** } ! lua_remove(L, -1); // remove metatable we got from wxluaT_get // ------------------------------------------------------------------ --- 750,754 ---- } ! lua_remove(L, -1); // remove metatable we got from wxluaR_getref() // ------------------------------------------------------------------ *************** *** 833,837 **** *ptr = wxlClass; ! wxluaT_get(L, iTag); lua_setmetatable(L, -2); --- 833,837 ---- *ptr = wxlClass; ! wxluaR_getref(L, iTag); lua_setmetatable(L, -2); Index: wxlcallb.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlcallb.cpp,v retrieving revision 1.43 retrieving revision 1.44 diff -C2 -d -r1.43 -r1.44 *** wxlcallb.cpp 30 Nov 2007 23:00:07 -0000 1.43 --- wxlcallb.cpp 4 Dec 2007 05:20:28 -0000 1.44 *************** *** 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, --- 52,56 ---- // create a reference to the Lua event handler function if (lua_func_stack_idx != WXLUACALLBACK_NOROUTINE) ! m_routine = m_wxlState.wxluaR_Ref(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, &wxlua_lreg_refs_key); // delete the reference to this handler m_wxlState.RemoveTrackedCallback(this); --- 64,68 ---- if (m_wxlState.Ok()) { ! m_wxlState.wxluaR_Unref(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, &wxlua_lreg_refs_key)) { wxlState.lua_PushValue(LUA_GLOBALSINDEX); --- 131,135 ---- wxlState.lua_CheckStack(LUA_MINSTACK); int oldTop = wxlState.lua_GetTop(); ! if (wxlState.wxluaR_GetRef(m_routine, &wxlua_lreg_refs_key)) { wxlState.lua_PushValue(LUA_GLOBALSINDEX); *************** *** 200,204 **** { // clear the metatable for the copy of the we are tracking (clears it for all copies too) ! wxluaT_cleartrackedmetatable(m_wxlState.GetLuaState(), m_window); // Now remove the object since it's gone m_wxlState.RemoveTrackedObject(m_window, wxLuaState::CLEAR_TRACKED_OBJECT|wxLuaState::CLEAR_DERIVED_METHODS); --- 200,204 ---- { // clear the metatable for the copy of the we are tracking (clears it for all copies too) ! wxluaO_cleartrackedmetatable(m_wxlState.GetLuaState(), m_window); // Now remove the object since it's gone m_wxlState.RemoveTrackedObject(m_window, wxLuaState::CLEAR_TRACKED_OBJECT|wxLuaState::CLEAR_DERIVED_METHODS); *************** *** 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(); } --- 227,231 ---- // remove the ref to the routine since we're clearing the wxLuaState // See ~wxLuaCallback ! m_wxlState.wxluaR_Unref(wxlCallback->GetLuaRoutine(), &wxlua_lreg_refs_key); wxlCallback->ClearwxLuaState(); } Index: wxlua_bind.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlua_bind.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** wxlua_bind.cpp 17 Nov 2007 00:15:03 -0000 1.9 --- wxlua_bind.cpp 4 Dec 2007 05:20:28 -0000 1.10 *************** *** 1,4 **** // --------------------------------------------------------------------------- ! // This file was generated by genwxbind.lua // // Any changes made to this file may be lost when file is regenerated. --- 1,4 ---- // --------------------------------------------------------------------------- ! // This file was generated by genwxbind.lua // // Any changes made to this file may be lost when file is regenerated. *************** *** 864,868 **** // this may a wxLua data if (ltype == LUA_TUSERDATA) ! wxluaarg_tag = wxluaT_tag(L, 1); // I guess it wasn't or isn't a userdata --- 864,868 ---- // this may a wxLua data if (ltype == LUA_TUSERDATA) ! wxluaarg_tag = wxluaT_gettag(L, 1); // I guess it wasn't or isn't a userdata *************** *** 965,969 **** { "wxLUA_CHECK_VERSION_FULL", WXLUAMETHOD_CFUNCTION, s_wxluafunc_wxLua_function_wxLUA_CHECK_VERSION_FULL, 1, NULL }, ! { 0, 0, 0, 0 }, }; count = sizeof(functionList)/sizeof(wxLuaBindMethod) - 1; --- 965,969 ---- { "wxLUA_CHECK_VERSION_FULL", WXLUAMETHOD_CFUNCTION, s_wxluafunc_wxLua_function_wxLUA_CHECK_VERSION_FULL, 1, NULL }, ! { 0, 0, 0, 0 }, }; count = sizeof(functionList)/sizeof(wxLuaBindMethod) - 1; *************** *** 981,988 **** static wxLuaBindClass classList[] = { ! { "wxLuaObject", wxLuaObject_methods, wxLuaObject_methodCount, CLASSINFO(wxLuaObject), &s_wxluatag_wxLuaObject, "wxObject", NULL ,s_wxluadefineArray_None, 0, }, ! { "wxLuaState", wxLuaState_methods, wxLuaState_methodCount, CLASSINFO(wxLuaState), &s_wxluatag_wxLuaState, "wxObject", NULL ,s_wxluadefineArray_None, 0, }, ! { 0, 0, 0, 0, 0, 0, 0 }, }; count = sizeof(classList)/sizeof(wxLuaBindClass) - 1; --- 981,988 ---- static wxLuaBindClass classList[] = { ! { "wxLuaObject", wxLuaObject_methods, wxLuaObject_methodCount, CLASSINFO(wxLuaObject), &s_wxluatag_wxLuaObject, "wxObject", NULL ,s_wxluadefineArray_None, 0, }, ! { "wxLuaState", wxLuaState_methods, wxLuaState_methodCount, CLASSINFO(wxLuaState), &s_wxluatag_wxLuaState, "wxObject", NULL ,s_wxluadefineArray_None, 0, }, ! { 0, 0, 0, 0, 0, 0, 0 }, }; count = sizeof(classList)/sizeof(wxLuaBindClass) - 1; |