From: John L. <jr...@us...> - 2007-06-14 23:59:53
|
Update of /cvsroot/wxlua/wxLua/modules/wxlua/src In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv16698/wxLua/modules/wxlua/src Modified Files: wxlbind.cpp wxlcallb.cpp wxlstate.cpp wxlua.cpp wxlua_bind.cpp Log Message: Add "voidptr_long" binding tag to allow using void* as a number Speed up bindings by using numbers as keys in the registry (avoid lua doing a string copy) Get rid of wxLuaState::GetXXXTag functions, something better needs to be implemented, using global vars for the few tags that we really use often now Allow the wxLuaStackDialog to be able to show lua's registry lots of cleanup in bindings.wx.lua Index: wxlua.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlua.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** wxlua.cpp 14 Jun 2007 01:23:19 -0000 1.1 --- wxlua.cpp 14 Jun 2007 23:59:48 -0000 1.2 *************** *** 67,75 **** int s_wxluatag_wxLuaObject = -1; ! static wxLuaArgTag s_wxluatagArray_wxLua_wxLuaObject_GetAllocationFlags[] = { &s_wxluatag_wxLuaObject, NULL }; ! static int LUACALL wxLua_wxLuaObject_GetAllocationFlags(lua_State *L); ! static wxLuaBindCFunc s_wxluafunc_wxLua_wxLuaObject_GetAllocationFlags[1] = {{ wxLua_wxLuaObject_GetAllocationFlags, WXLUAMETHOD_METHOD, 1, 1, s_wxluatagArray_wxLua_wxLuaObject_GetAllocationFlags }}; ! // int GetAllocationFlags() const ! static int LUACALL wxLua_wxLuaObject_GetAllocationFlags(lua_State *L) { wxLuaState wxlState(L); --- 67,75 ---- int s_wxluatag_wxLuaObject = -1; ! static wxLuaArgTag s_wxluatagArray_wxLua_wxLuaObject_GetAllocationFlag[] = { &s_wxluatag_wxLuaObject, NULL }; ! static int LUACALL wxLua_wxLuaObject_GetAllocationFlag(lua_State *L); ! static wxLuaBindCFunc s_wxluafunc_wxLua_wxLuaObject_GetAllocationFlag[1] = {{ wxLua_wxLuaObject_GetAllocationFlag, WXLUAMETHOD_METHOD, 1, 1, s_wxluatagArray_wxLua_wxLuaObject_GetAllocationFlag }}; ! // int GetAllocationFlag() const ! static int LUACALL wxLua_wxLuaObject_GetAllocationFlag(lua_State *L) { wxLuaState wxlState(L); *************** *** 77,82 **** // get this wxLuaObject * self = (wxLuaObject *)wxlState.GetUserDataType(1, s_wxluatag_wxLuaObject); ! // call GetAllocationFlags ! returns = self->GetAllocationFlags(); // push the result number lua_pushnumber(L, returns); --- 77,82 ---- // get this wxLuaObject * self = (wxLuaObject *)wxlState.GetUserDataType(1, s_wxluatag_wxLuaObject); ! // call GetAllocationFlag ! returns = (self->GetAllocationFlag()); // push the result number lua_pushnumber(L, returns); *************** *** 103,126 **** - static wxLuaArgTag s_wxluatagArray_wxLua_wxLuaObject_HasAllocationFlag[] = { &s_wxluatag_wxLuaObject, &s_wxluaarg_Integer, NULL }; - static int LUACALL wxLua_wxLuaObject_HasAllocationFlag(lua_State *L); - static wxLuaBindCFunc s_wxluafunc_wxLua_wxLuaObject_HasAllocationFlag[1] = {{ wxLua_wxLuaObject_HasAllocationFlag, WXLUAMETHOD_METHOD, 2, 2, s_wxluatagArray_wxLua_wxLuaObject_HasAllocationFlag }}; - // bool HasAllocationFlag(wxLuaObject_Type flag) - static int LUACALL wxLua_wxLuaObject_HasAllocationFlag(lua_State *L) - { - wxLuaState wxlState(L); - bool returns; - // wxLuaObject_Type flag - wxLuaObject_Type flag = (wxLuaObject_Type)wxlua_getintegertype(L, 2); - // get this - wxLuaObject * self = (wxLuaObject *)wxlState.GetUserDataType(1, s_wxluatag_wxLuaObject); - // call HasAllocationFlag - returns = self->HasAllocationFlag(flag); - // push the result flag - lua_pushboolean(L, returns); - - return 1; - } - static wxLuaArgTag s_wxluatagArray_wxLua_wxLuaObject_SetObject[] = { &s_wxluatag_wxLuaObject, NULL }; static int LUACALL wxLua_wxLuaObject_SetObject(lua_State *L); --- 103,106 ---- *************** *** 180,186 **** // Map Lua Class Methods to C Binding Functions wxLuaBindMethod wxLuaObject_methods[] = { ! { "GetAllocationFlags", WXLUAMETHOD_METHOD, s_wxluafunc_wxLua_wxLuaObject_GetAllocationFlags, 1, NULL }, { "GetObject", WXLUAMETHOD_METHOD, s_wxluafunc_wxLua_wxLuaObject_GetObject, 1, NULL }, - { "HasAllocationFlag", WXLUAMETHOD_METHOD, s_wxluafunc_wxLua_wxLuaObject_HasAllocationFlag, 1, NULL }, { "SetObject", WXLUAMETHOD_METHOD, s_wxluafunc_wxLua_wxLuaObject_SetObject, 1, NULL }, { "delete", WXLUAMETHOD_METHOD|WXLUAMETHOD_DELETE, s_wxluafunc_wxLua_wxLuaObject_delete, 1, NULL }, --- 160,165 ---- // Map Lua Class Methods to C Binding Functions wxLuaBindMethod wxLuaObject_methods[] = { ! { "GetAllocationFlag", WXLUAMETHOD_METHOD, s_wxluafunc_wxLua_wxLuaObject_GetAllocationFlag, 1, NULL }, { "GetObject", WXLUAMETHOD_METHOD, s_wxluafunc_wxLua_wxLuaObject_GetObject, 1, NULL }, { "SetObject", WXLUAMETHOD_METHOD, s_wxluafunc_wxLua_wxLuaObject_SetObject, 1, NULL }, { "delete", WXLUAMETHOD_METHOD|WXLUAMETHOD_DELETE, s_wxluafunc_wxLua_wxLuaObject_delete, 1, NULL }, Index: wxlstate.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlstate.cpp,v retrieving revision 1.112 retrieving revision 1.113 diff -C2 -d -r1.112 -r1.113 *** wxlstate.cpp 14 Jun 2007 12:23:04 -0000 1.112 --- wxlstate.cpp 14 Jun 2007 23:59:48 -0000 1.113 *************** *** 263,267 **** int nTop = lua_gettop(L); // this is where the value is ! wxlua_pushstring_wxLuaReferences(L); // push name of table to get as key lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push result (the refs table) --- 263,267 ---- int nTop = lua_gettop(L); // this is where the value is ! wxlua_pushkey_wxLuaReferences(L); // push name of table to get as key lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push result (the refs table) *************** *** 281,285 **** return true; ! wxlua_pushstring_wxLuaReferences(L); // push name of table to get as key lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push result (the refs table) --- 281,285 ---- 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) *************** *** 295,299 **** return false; ! wxlua_pushstring_wxLuaReferences(L);// push name of table to get as key lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push result (the refs table) --- 295,299 ---- 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) *************** *** 356,360 **** if (lua_getmetatable(L, stack_idx) != 0) // see tnewtag { ! lua_pushlstring(L, "tag", 3); // get t["tag"] lua_rawget(L, -2); //if (lua_isnumber(L, -1)) // Note: lua_tonumber returns 0 == WXLUA_NOTAG if it's not a number --- 356,360 ---- if (lua_getmetatable(L, stack_idx) != 0) // see tnewtag { ! 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 *************** *** 387,391 **** int tag = wxlua_tinsert(L, -1); // insert the table into the wxLuaReferences registry table ! lua_pushlstring(L, "tag", 3); // add t["tag"] = tag to new table lua_pushnumber(L, tag); lua_rawset(L, -3); --- 387,391 ---- int tag = wxlua_tinsert(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); *************** *** 425,429 **** int tag = wxlua_tinsert(L, -1); // insert the table into the wxLuaReferences registry table ! lua_pushlstring(L, "tag", 3); // add t["tag"] = tag to new table lua_pushnumber(L, tag); lua_rawset(L, -3); --- 425,429 ---- int tag = wxlua_tinsert(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); *************** *** 480,485 **** if (wxlua_tget(L, class_tag) && lua_istable(L, -1)) { ! // t[class_tag] = { ["wxLuaBindClass"] = lightuserdata wxLuaBindClass... (or nil if not a class tag) ! lua_pushstring(L, "wxLuaBindClass"); lua_rawget(L, -2); const wxLuaBindClass* wxlClass = (wxLuaBindClass *)lua_touserdata(L, -1); // actually lightuserdata --- 480,485 ---- if (wxlua_tget(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 *************** *** 495,499 **** const wxLuaBindClass* LUACALL wxlua_tgetclass(lua_State* L, const char* class_name) { ! wxlua_pushstring_wxLuaClasses(L); lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push result (the classes table) --- 495,499 ---- const wxLuaBindClass* LUACALL wxlua_tgetclass(lua_State* L, const char* class_name) { ! wxlua_pushkey_wxLuaClasses(L); lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push result (the classes table) *************** *** 784,788 **** bool wxlua_setderivedmethod(lua_State* L, void *pObject, const char *method_name, wxLuaObject* wxlObj) { ! wxlua_pushstring_wxLuaDerivedMethods(L); lua_rawget( L, LUA_REGISTRYINDEX ); // pop key, push table --- 784,788 ---- bool 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 *************** *** 837,841 **** bool found = false; ! wxlua_pushstring_wxLuaDerivedMethods(L); lua_rawget( L, LUA_REGISTRYINDEX ); // pop key, push table --- 837,841 ---- bool found = false; ! wxlua_pushkey_wxLuaDerivedMethods(L); lua_rawget( L, LUA_REGISTRYINDEX ); // pop key, push table *************** *** 881,885 **** bool found = false; ! wxlua_pushstring_wxLuaDerivedMethods(L); lua_rawget( L, LUA_REGISTRYINDEX ); // pop key, push table --- 881,885 ---- bool found = false; ! wxlua_pushkey_wxLuaDerivedMethods(L); lua_rawget( L, LUA_REGISTRYINDEX ); // pop key, push table *************** *** 1057,1066 **** wxLuaStateData::wxLuaStateData() :m_bindings_registered(false), - m_wxluatag_wxLuaFunction(0), - m_wxluatag_NULL(0), - m_wxluatag_wxWinDestroyTable(0), - m_wxluatag_wxEvent(0), - m_wxluatag_wxWindow(0), - m_wxluatag_wxString(0), m_callbase_func(false), m_inEventType(wxEVT_NULL), --- 1057,1060 ---- *************** *** 1258,1270 **** } ! wxlua_pushstring_wxLuaReferences(m_lua_State); lua_pushnil(m_lua_State); lua_rawset(m_lua_State, LUA_REGISTRYINDEX); ! wxlua_pushstring_wxLuaClasses(m_lua_State); lua_pushnil(m_lua_State); lua_rawset(m_lua_State, LUA_REGISTRYINDEX); ! //wxlua_pushstring_wxLuaDerivedMethods(m_lua_State); // gc will delete them //lua_pushnil(m_lua_State); //lua_rawset(m_lua_State, LUA_REGISTRYINDEX); --- 1252,1264 ---- } ! 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); *************** *** 1285,1289 **** // try to get the state we've stored ! wxlua_pushstring_wxLuaStateRefData(L); lua_rawget( L, LUA_REGISTRYINDEX ); --- 1279,1283 ---- // try to get the state we've stored ! wxlua_pushkey_wxLuaStateRefData(L); lua_rawget( L, LUA_REGISTRYINDEX ); *************** *** 1342,1346 **** // Stick us into the lua_State - push key, value ! wxlua_pushstring_wxLuaStateRefData(L); lua_pushlightuserdata( L, (void*)m_refData ); lua_rawset( L, LUA_REGISTRYINDEX ); // set the value --- 1336,1340 ---- // Stick us into the lua_State - push key, value ! wxlua_pushkey_wxLuaStateRefData(L); lua_pushlightuserdata( L, (void*)m_refData ); lua_rawset( L, LUA_REGISTRYINDEX ); // set the value *************** *** 1379,1383 **** // Stick us into the lua_State - push key, value ! wxlua_pushstring_wxLuaStateRefData(L); lua_pushlightuserdata( L, (void*)m_refData ); lua_rawset( L, LUA_REGISTRYINDEX ); // set the value --- 1373,1377 ---- // Stick us into the lua_State - push key, value ! wxlua_pushkey_wxLuaStateRefData(L); lua_pushlightuserdata( L, (void*)m_refData ); lua_rawset( L, LUA_REGISTRYINDEX ); // set the value *************** *** 1846,1865 **** // Stick us into the lua_State - push key, value // make sure we're there, even though we might have already done this. ! wxlua_pushstring_wxLuaStateRefData(L); lua_pushlightuserdata( L, (void*)m_refData ); lua_rawset( L, LUA_REGISTRYINDEX ); // set the value // create the wxLuaReferences table in registry ! wxlua_pushstring_wxLuaReferences(L); lua_newtable(L); lua_rawset(L, LUA_REGISTRYINDEX); // set the value // create the wxLuaClasses table in the registry ! wxlua_pushstring_wxLuaClasses(L); lua_newtable(L); lua_rawset(L, LUA_REGISTRYINDEX); // Create a table for overridden methods for C++ objects ! wxlua_pushstring_wxLuaDerivedMethods(L); lua_newtable(L); lua_rawset( L, LUA_REGISTRYINDEX ); // set the value --- 1840,1859 ---- // Stick us into the lua_State - push key, value // make sure we're there, even though we might have already done this. ! wxlua_pushkey_wxLuaStateRefData(L); lua_pushlightuserdata( L, (void*)m_refData ); lua_rawset( L, LUA_REGISTRYINDEX ); // set the value // 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++ objects ! wxlua_pushkey_wxLuaDerivedMethods(L); lua_newtable(L); lua_rawset( L, LUA_REGISTRYINDEX ); // set the value *************** *** 1908,1917 **** if (registerTypes) { ! M_WXLSTATEDATA->m_wxlStateData->m_wxluatag_wxLuaFunction = tnewtag(); ! M_WXLSTATEDATA->m_wxlStateData->m_wxluatag_wxWinDestroyTable = tnewweaktag(false, true); } ! tsettagmethod(GetLuaStateData()->m_wxluatag_wxLuaFunction, "__gc", wxlua_gc_wxLuaFunction); ! tsettagmethod(GetLuaStateData()->m_wxluatag_wxLuaFunction, "__call", wxlua_call_wxLuaFunction); } --- 1902,1926 ---- if (registerTypes) { ! g_wxluatag_wxLuaFunction = tnewtag(); ! g_wxluatag_wxWinDestroyTable = tnewweaktag(false, true); } ! tsettagmethod(g_wxluatag_wxLuaFunction, "__gc", wxlua_gc_wxLuaFunction); ! tsettagmethod(g_wxluatag_wxLuaFunction, "__call", wxlua_call_wxLuaFunction); ! ! ! const wxLuaBindClass* wxlClass = NULL; ! ! wxlClass = GetLuaClass("wxEvent"); ! wxCHECK_RET(wxlClass, wxT("wxEvent lua tag is missing in wxLuaState, forgot to add wxWidgets binding?")); ! g_wxluatag_wxEvent = *wxlClass->class_tag; ! ! wxlClass = GetLuaClass("wxString"); ! wxCHECK_RET(wxlClass, wxT("wxString lua tag is missing in wxLuaState, forgot to add wxWidgets binding?")); ! g_wxluatag_wxString = *wxlClass->class_tag; ! ! wxlClass = GetLuaClass("wxWindow"); ! wxCHECK_RET(wxlClass, wxT("wxWindow lua tag is missing in wxLuaState, forgot to add wxWidgets binding?")); ! g_wxluatag_wxWindow = *wxlClass->class_tag; } *************** *** 2026,2086 **** return M_WXLSTATEDATA->m_wxlStateData->m_bindings_registered; } - int wxLuaState::GetwxLuaFunctionTag() const - { - wxCHECK_MSG(GetRefData() != NULL, 0, wxT("Invalid wxLuaState")); - return M_WXLSTATEDATA->m_wxlStateData->m_wxluatag_wxLuaFunction; - } - int wxLuaState::GetLuaNULLTag() const - { - wxCHECK_MSG(GetRefData() != NULL, 0, wxT("Invalid wxLuaState")); - return M_WXLSTATEDATA->m_wxlStateData->m_wxluatag_NULL; - } - int wxLuaState::GetLuaWinDestroyTableTag() const - { - wxCHECK_MSG(GetRefData() != NULL, 0, wxT("Invalid wxLuaState")); - return M_WXLSTATEDATA->m_wxlStateData->m_wxluatag_wxWinDestroyTable; - } - int wxLuaState::GetwxEventTag() const - { - wxCHECK_MSG(Ok(), 0, wxT("Invalid wxLuaState")); - - // Find the wxEvent tag once and store it for later use - if (M_WXLSTATEDATA->m_wxlStateData->m_wxluatag_wxEvent == 0) - { - const wxLuaBindClass* luaClass = GetLuaClass("wxEvent"); - wxCHECK_MSG(luaClass, 0, wxT("wxEvent lua tag is missing in wxLuaState, forgot to add wxWidgets binding?")); - M_WXLSTATEDATA->m_wxlStateData->m_wxluatag_wxEvent = *luaClass->class_tag; - } - - return M_WXLSTATEDATA->m_wxlStateData->m_wxluatag_wxEvent; - } - int wxLuaState::GetwxWindowTag() const - { - wxCHECK_MSG(Ok(), 0, wxT("Invalid wxLuaState")); - - // Find the wxWindow tag once and store it for later use - if (M_WXLSTATEDATA->m_wxlStateData->m_wxluatag_wxWindow == 0) - { - const wxLuaBindClass* luaClass = GetLuaClass("wxWindow"); - wxCHECK_MSG(luaClass, 0, wxT("wxWindow lua tag is missing in wxLuaState, forgot to add wxWidgets binding?")); - M_WXLSTATEDATA->m_wxlStateData->m_wxluatag_wxWindow = *luaClass->class_tag; - } - - return M_WXLSTATEDATA->m_wxlStateData->m_wxluatag_wxWindow; - } - int wxLuaState::GetwxStringTag() const - { - wxCHECK_MSG(Ok(), 0, wxT("Invalid wxLuaState")); - - // Find the wxString tag once and store it for later use - if (M_WXLSTATEDATA->m_wxlStateData->m_wxluatag_wxString == 0) - { - const wxLuaBindClass* luaClass = GetLuaClass("wxString"); - wxCHECK_MSG(luaClass, 0, wxT("wxString lua tag is missing in wxLuaState, forgot to add wxWidgets binding?")); - M_WXLSTATEDATA->m_wxlStateData->m_wxluatag_wxString = *luaClass->class_tag; - } - - return M_WXLSTATEDATA->m_wxlStateData->m_wxluatag_wxString; - } void wxLuaState::SetCallBaseClassFunction(bool call_base) --- 2035,2038 ---- *************** *** 2317,2326 **** lua_State* L = M_WXLSTATEDATA->m_lua_State; ! const wxLuaBindClass* wxlClass = wxlua_tgetclass(L, "wxArrayString"); ! if (wxlClass && (IsDerivedClass(wxluaarg_tag, *wxlClass->class_tag) >= 0)) return 1; ! wxlClass = wxlua_tgetclass(L, "wxArrayInt"); ! if (wxlClass && (IsDerivedClass(wxluaarg_tag, *wxlClass->class_tag) >= 0)) return 1; } --- 2269,2280 ---- lua_State* L = M_WXLSTATEDATA->m_lua_State; ! const wxLuaBindClass* wxlClass = wxlua_tgetclass(L, wxluaarg_tag); ! ! const wxLuaBindClass* arrClass = wxlua_tgetclass(L, "wxArrayString"); ! if (wxlClass && (wxlua_isderivedclass(wxlClass, arrClass) >= 0)) return 1; ! arrClass = wxlua_tgetclass(L, "wxArrayInt"); ! if (wxlClass && (wxlua_isderivedclass(wxlClass, arrClass) >= 0)) return 1; } *************** *** 2338,2344 **** { int stack_tag = wxlua_ttag(L, stack_idx); ! if ((GetLuaNULLTag() == stack_tag) || // FIXME, how to check when NULL is valid or not? ! (GetwxLuaFunctionTag() == stack_tag) || ! ((tag == WXLUAARG_String) && (IsDerivedClass(stack_tag, GetwxStringTag()) >= 0)) || (IsDerivedClass(stack_tag, tag) >= 0)) return true; --- 2292,2298 ---- { int stack_tag = wxlua_ttag(L, stack_idx); ! if ((g_wxluatag_NULL == stack_tag) || // FIXME, how to check when NULL is valid or not? ! (g_wxluatag_wxLuaFunction == stack_tag) || ! ((tag == WXLUAARG_String) && (IsDerivedClass(stack_tag, g_wxluatag_wxString) >= 0)) || (IsDerivedClass(stack_tag, tag) >= 0)) return true; *************** *** 2357,2366 **** int stack_tag = ttag(stack_idx); ! if (M_WXLSTATEDATA->m_wxlStateData->m_wxluatag_wxLuaFunction == stack_tag) { wxLuaFunction *pFunction = (wxLuaFunction *)ttouserdata(stack_idx); return pFunction->GetObject(); } ! else if (M_WXLSTATEDATA->m_wxlStateData->m_wxluatag_NULL == stack_tag) return NULL; else if (IsDerivedClass(stack_tag, tag) >= 0) --- 2311,2320 ---- int stack_tag = ttag(stack_idx); ! if (g_wxluatag_wxLuaFunction == stack_tag) { wxLuaFunction *pFunction = (wxLuaFunction *)ttouserdata(stack_idx); return pFunction->GetObject(); } ! else if (g_wxluatag_NULL == stack_tag) return NULL; else if (IsDerivedClass(stack_tag, tag) >= 0) *************** *** 2382,2386 **** // if the object we are referencing is derived from wxWindow ! if (IsDerivedClass(tag, GetwxWindowTag()) >= 0) { wxWindow* win = wxDynamicCast(data, wxWindow); --- 2336,2340 ---- // if the object we are referencing is derived from wxWindow ! if (IsDerivedClass(tag, g_wxluatag_wxWindow) >= 0) { wxWindow* win = wxDynamicCast(data, wxWindow); *************** *** 2446,2450 **** int stack_tag = wxlua_ttag(L, stack_idx); ! if (IsDerivedClass(stack_tag, GetwxStringTag()) >= 0) { wxString* wxstr = (wxString*)wxlua_ttouserdata(L, stack_idx, false); --- 2400,2404 ---- int stack_tag = wxlua_ttag(L, stack_idx); ! if (IsDerivedClass(stack_tag, g_wxluatag_wxString) >= 0) { wxString* wxstr = (wxString*)wxlua_ttouserdata(L, stack_idx, false); *************** *** 2486,2490 **** { int stack_tag = wxlua_ttag(L, stack_idx); ! return (IsDerivedClass(stack_tag, GetwxStringTag()) >= 0); } --- 2440,2444 ---- { int stack_tag = wxlua_ttag(L, stack_idx); ! return (IsDerivedClass(stack_tag, g_wxluatag_wxString) >= 0); } *************** *** 2696,2702 **** return wxlua_getwxluatypename(tag); ! if (tag == M_WXLSTATEDATA->m_wxlStateData->m_wxluatag_NULL) return wxT("NULL"); ! if (tag == M_WXLSTATEDATA->m_wxlStateData->m_wxluatag_wxLuaFunction) return wxT("wxLuaFunction"); --- 2650,2656 ---- return wxlua_getwxluatypename(tag); ! if (tag == g_wxluatag_NULL) return wxT("NULL"); ! if (tag == g_wxluatag_wxLuaFunction) return wxT("wxLuaFunction"); *************** *** 3620,3624 **** { is_ok = (IsUserDataType(arg_lua, tag) || ! (tag == M_WXLSTATEDATA->m_wxlStateData->m_wxluatag_NULL)) ? 1 : 0; } --- 3574,3578 ---- { is_ok = (IsUserDataType(arg_lua, tag) || ! (tag == g_wxluatag_NULL)) ? 1 : 0; } Index: wxlbind.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlbind.cpp,v retrieving revision 1.75 retrieving revision 1.76 diff -C2 -d -r1.75 -r1.76 *** wxlbind.cpp 14 Jun 2007 05:02:48 -0000 1.75 --- wxlbind.cpp 14 Jun 2007 23:59:48 -0000 1.76 *************** *** 43,46 **** --- 43,53 ---- int s_wxluaarg_Integer = WXLUAARG_Integer; + int g_wxluatag_wxLuaFunction = 0; + int g_wxluatag_wxWinDestroyTable = 0; + int g_wxluatag_NULL = 0; + int g_wxluatag_wxEvent = 0; + int g_wxluatag_wxWindow = 0; + int g_wxluatag_wxString = 0; + //----------------------------------------------------------------------------- // wxLuaFunction *************** *** 67,71 **** wxCHECK_MSG(wxlState.Ok(), 0, wxT("Invalid wxLuaState")); ! if (wxlua_iswxuserdata(L, 1) && (wxlua_ttag(L, 1) == wxlState.GetwxLuaFunctionTag())) { wxLuaFunction *wxlFunction = (wxLuaFunction *)wxlua_ttouserdata(L, 1, true); --- 74,78 ---- wxCHECK_MSG(wxlState.Ok(), 0, wxT("Invalid wxLuaState")); ! if (wxlua_iswxuserdata(L, 1) && (wxlua_ttag(L, 1) == g_wxluatag_wxLuaFunction)) { wxLuaFunction *wxlFunction = (wxLuaFunction *)wxlua_ttouserdata(L, 1, true); *************** *** 81,85 **** wxCHECK_MSG(wxlState.Ok(), 0, wxT("Invalid wxLuaState")); ! if (wxlua_iswxuserdata(L, 1) && (wxlua_ttag(L, 1) == wxlState.GetwxLuaFunctionTag())) { wxLuaFunction *wxlFunction = (wxLuaFunction *)wxlua_ttouserdata(L, 1, false); --- 88,92 ---- wxCHECK_MSG(wxlState.Ok(), 0, wxT("Invalid wxLuaState")); ! if (wxlua_iswxuserdata(L, 1) && (wxlua_ttag(L, 1) == g_wxluatag_wxLuaFunction)) { wxLuaFunction *wxlFunction = (wxLuaFunction *)wxlua_ttouserdata(L, 1, false); *************** *** 102,106 **** wxLuaObject::wxLuaObject(const wxLuaState& wxlState, int stack_idx) : m_wxlState(new wxLuaState(wxlState)), ! m_bool(false), m_int(0), m_alloc_flags(wxLUAOBJECT_NONE) { // set up the reference to the item on the stack --- 109,115 ---- wxLuaObject::wxLuaObject(const wxLuaState& wxlState, int stack_idx) : m_wxlState(new wxLuaState(wxlState)), ! m_alloc_flag(wxLUAOBJECT_NONE), ! m_bool(false), m_int(0), m_string(NULL), m_arrayInt(NULL) ! { // set up the reference to the item on the stack *************** *** 110,113 **** --- 119,127 ---- wxLuaObject::~wxLuaObject() { + if (m_alloc_flag == wxLUAOBJECT_STRING) + delete m_string; + else if (m_alloc_flag == wxLUAOBJECT_ARRAYINT) + delete m_arrayInt; + // 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()) *************** *** 122,135 **** } - int wxLuaObject::SetAllocationFlag(wxLuaObject_Type flag, bool set) - { - if (set) - m_alloc_flags |= flag; - else - m_alloc_flags &= (~ int(flag)); - - return m_alloc_flags; - } - bool wxLuaObject::GetObject() { --- 136,139 ---- *************** *** 137,158 **** lua_State* L = m_wxlState->GetLuaState(); ! if (HasAllocationFlag(wxLUAOBJECT_BOOL)) { lua_pushboolean(L, m_bool); return true; } ! else if (HasAllocationFlag(wxLUAOBJECT_INT)) { lua_pushnumber(L, m_int); return true; } ! else if (HasAllocationFlag(wxLUAOBJECT_STRING)) { ! lua_pushstring(L, wx2lua(m_string)); return true; } ! else if (HasAllocationFlag(wxLUAOBJECT_ARRAYINT)) { ! wxlua_pushwxArrayInttable(L, m_arrayInt); return true; } --- 141,162 ---- lua_State* L = m_wxlState->GetLuaState(); ! if (m_alloc_flag == wxLUAOBJECT_BOOL) { lua_pushboolean(L, m_bool); return true; } ! else if (m_alloc_flag == wxLUAOBJECT_INT) { lua_pushnumber(L, m_int); return true; } ! else if (m_alloc_flag == wxLUAOBJECT_STRING) { ! lua_pushstring(L, wx2lua(*m_string)); return true; } ! else if (m_alloc_flag == wxLUAOBJECT_ARRAYINT) { ! wxlua_pushwxArrayInttable(L, *m_arrayInt); return true; } *************** *** 166,185 **** { wxCHECK_RET(m_wxlState->Ok(), wxT("Invalid wxLuaState")); - if (m_wxlState->Ok() && (m_reference != LUA_NOREF)) // FIXME should this error out? - m_wxlState->tremove(m_reference); ! m_reference = LUA_NOREF; ! if (m_wxlState->Ok()) ! m_reference = m_wxlState->tinsert(stack_idx); } bool *wxLuaObject::GetBoolPtr() { ! wxCHECK_MSG(m_wxlState->Ok(), false, wxT("Invalid wxLuaState")); ! if (m_wxlState->Ok() && (m_reference != LUA_NOREF) && GetObject()) { ! m_bool = (lua_toboolean(m_wxlState->GetLuaState(), -1) != 0); ! m_alloc_flags |= wxLUAOBJECT_BOOL; m_wxlState->lua_Pop(1); } --- 170,189 ---- { wxCHECK_RET(m_wxlState->Ok(), wxT("Invalid wxLuaState")); ! if (m_reference != LUA_NOREF) // FIXME should this error out? ! m_wxlState->tremove(m_reference); ! m_reference = m_wxlState->tinsert(stack_idx); } bool *wxLuaObject::GetBoolPtr() { ! wxCHECK_MSG(m_wxlState->Ok(), 0, wxT("Invalid wxLuaState")); ! wxCHECK_MSG(m_alloc_flag == wxLUAOBJECT_NONE, 0, wxT("wxLuaObject already initialized")); ! ! if ((m_reference != LUA_NOREF) && GetObject()) { ! m_bool = (lua_toboolean(m_wxlState->GetLuaState(), -1) != 0); ! m_alloc_flag = wxLUAOBJECT_BOOL; m_wxlState->lua_Pop(1); } *************** *** 190,197 **** { wxCHECK_MSG(m_wxlState->Ok(), false, wxT("Invalid wxLuaState")); ! if (m_wxlState->Ok() && (m_reference != LUA_NOREF) && GetObject()) { ! m_int = (int) lua_tonumber(m_wxlState->GetLuaState(), -1); ! m_alloc_flags |= wxLUAOBJECT_INT; m_wxlState->lua_Pop(1); } --- 194,203 ---- { wxCHECK_MSG(m_wxlState->Ok(), false, wxT("Invalid wxLuaState")); ! wxCHECK_MSG(m_alloc_flag == wxLUAOBJECT_NONE, 0, wxT("wxLuaObject already initialized")); ! ! if ((m_reference != LUA_NOREF) && GetObject()) { ! m_int = (int)lua_tonumber(m_wxlState->GetLuaState(), -1); ! m_alloc_flag = wxLUAOBJECT_INT; m_wxlState->lua_Pop(1); } *************** *** 202,213 **** { wxCHECK_MSG(m_wxlState->Ok(), false, wxT("Invalid wxLuaState")); ! if (m_wxlState->Ok() && (m_reference != LUA_NOREF) && GetObject()) { ! m_string = lua2wx(lua_tostring(m_wxlState->GetLuaState(), -1)); ! m_alloc_flags |= wxLUAOBJECT_STRING; m_wxlState->lua_Pop(1); } ! return &m_string; } --- 208,223 ---- { wxCHECK_MSG(m_wxlState->Ok(), false, wxT("Invalid wxLuaState")); ! wxCHECK_MSG(m_alloc_flag == wxLUAOBJECT_NONE, 0, wxT("wxLuaObject already initialized")); ! ! m_string = new wxString(); // create valid string for return ! ! if ((m_reference != LUA_NOREF) && GetObject()) { ! *m_string = lua2wx(lua_tostring(m_wxlState->GetLuaState(), -1)); ! m_alloc_flag = wxLUAOBJECT_STRING; m_wxlState->lua_Pop(1); } ! return m_string; } *************** *** 215,225 **** { wxCHECK_MSG(m_wxlState->Ok(), false, wxT("Invalid wxLuaState")); ! if (m_wxlState->Ok() && (m_reference != LUA_NOREF) && GetObject()) { ! m_wxlState->GetwxArrayInt(-1, m_arrayInt); ! m_alloc_flags |= wxLUAOBJECT_ARRAYINT; m_wxlState->lua_Pop(1); } ! return &m_arrayInt; } --- 225,239 ---- { wxCHECK_MSG(m_wxlState->Ok(), false, wxT("Invalid wxLuaState")); ! wxCHECK_MSG(m_alloc_flag == wxLUAOBJECT_NONE, 0, wxT("wxLuaObject already initialized")); ! ! m_arrayInt = new wxArrayInt(); // create valid array for return ! ! if ((m_reference != LUA_NOREF) && GetObject()) { ! m_wxlState->GetwxArrayInt(-1, *m_arrayInt); ! m_alloc_flag = wxLUAOBJECT_ARRAYINT; m_wxlState->lua_Pop(1); } ! return m_arrayInt; } *************** *** 327,331 **** result = 1; wxLuaFunction *wxlFunc = new wxLuaFunction(wxlMethod, wxlClass, pObject); ! wxlua_tpushusertag(L, wxlFunc, wxlState.GetwxLuaFunctionTag()); } } --- 341,345 ---- result = 1; wxLuaFunction *wxlFunc = new wxLuaFunction(wxlMethod, wxlClass, pObject); ! wxlua_tpushusertag(L, wxlFunc, g_wxluatag_wxLuaFunction); } } *************** *** 708,712 **** // store a lookup table for the class tags to wxLuaBindClass structs wxlua_tget(L, iTag); ! lua_pushstring(L, "wxLuaBindClass"); lua_pushlightuserdata(L, (void *)wxlClass); lua_rawset(L, -3); // t[name] = tag --- 722,726 ---- // store a lookup table for the class tags to wxLuaBindClass structs wxlua_tget(L, iTag); ! wxlua_pushkey_metatableClass(L); lua_pushlightuserdata(L, (void *)wxlClass); lua_rawset(L, -3); // t[name] = tag *************** *** 714,718 **** // store a lookup table for the class names to wxLuaBindClass structs ! wxlua_pushstring_wxLuaClasses(L); lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push result (the classes table) lua_pushstring(L, wxlClass->name); --- 728,732 ---- // store a lookup table for the class names to wxLuaBindClass structs ! wxlua_pushkey_wxLuaClasses(L); lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push result (the classes table) lua_pushstring(L, wxlClass->name); Index: wxlcallb.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlcallb.cpp,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** wxlcallb.cpp 12 Jun 2007 00:08:42 -0000 1.31 --- wxlcallb.cpp 14 Jun 2007 23:59:48 -0000 1.32 *************** *** 136,140 **** event_tag = *m_wxlBindEvent->class_tag; else ! event_tag = wxlState.GetwxEventTag(); // get the s_wxluatag_wxEvent wxlState.lua_CheckStack(LUA_MINSTACK); --- 136,140 ---- event_tag = *m_wxlBindEvent->class_tag; else ! event_tag = g_wxluatag_wxEvent; // get the s_wxluatag_wxEvent wxlState.lua_CheckStack(LUA_MINSTACK); *************** *** 186,190 **** // get a reference to the destroy handler table ! if (m_wxlState.tget(m_wxlState.GetLuaWinDestroyTableTag())) { // create a reference to object --- 186,190 ---- // get a reference to the destroy handler table ! if (m_wxlState.tget(g_wxluatag_wxWinDestroyTable)) { // create a reference to object *************** *** 237,241 **** // Note: do not remove from wxLuaState's destroyHandlerList here, wait 'till destructor ! if (m_wxlState.tget(m_wxlState.GetLuaWinDestroyTableTag())) { // clear the metatable reference in the lua proxy. --- 237,241 ---- // Note: do not remove from wxLuaState's destroyHandlerList here, wait 'till destructor ! if (m_wxlState.tget(g_wxluatag_wxWinDestroyTable)) { // clear the metatable reference in the lua proxy. Index: wxlua_bind.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlua_bind.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** wxlua_bind.cpp 14 Jun 2007 05:02:48 -0000 1.2 --- wxlua_bind.cpp 14 Jun 2007 23:59:48 -0000 1.3 *************** *** 160,164 **** int luatype = (int)wxlua_getnumbertype(L, 1); // call wxlua_iswxluatype ! returns = wxlua_iswxluatype(luatype, wxluaarg_tag); // push the result number lua_pushnumber(L, returns); --- 160,164 ---- int luatype = (int)wxlua_getnumbertype(L, 1); // call wxlua_iswxluatype ! returns = (wxlua_iswxluatype(luatype, wxluaarg_tag)); // push the result number lua_pushnumber(L, returns); |