From 0d2b1f4fb38cce60eafb73c5ae28c3a3335a35fb Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Mon, 25 Sep 2006 08:51:28 +0000 Subject: [PATCH] simplify; always create the table if it doesn't exist --- stepmania/src/LuaBinding.cpp | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/stepmania/src/LuaBinding.cpp b/stepmania/src/LuaBinding.cpp index da2e81cc70..4f5ed0c32c 100644 --- a/stepmania/src/LuaBinding.cpp +++ b/stepmania/src/LuaBinding.cpp @@ -77,23 +77,21 @@ bool LuaBinding::CheckLuaObjectType( lua_State *L, int narg, const char *szType, } } -static bool GetGlobalTable( Lua *L, bool bCreate ) +static void GetGlobalTable( Lua *L ) { lua_pushstring( L, "userdatas" ); lua_rawget( L, LUA_REGISTRYINDEX ); if( !lua_isnil(L, -1) ) - return true; + return; lua_pop( L, 1 ); - if( !bCreate ) - return false; /* Save it. */ lua_newtable( L ); lua_pushstring( L, "userdatas" ); lua_pushvalue( L, -2 ); lua_rawset( L, LUA_REGISTRYINDEX ); - return true; + return; } /* The object is on the stack. It's either a table or a userdata. @@ -109,7 +107,7 @@ void LuaBinding::ApplyDerivedType( Lua *L, const RString &sClassName, void *pSel if( iType == LUA_TTABLE ) { - GetGlobalTable( L, true ); + GetGlobalTable( L ); int iGlobalTable = lua_gettop( L ); /* If the table is already in the userdata table, then everything @@ -144,8 +142,7 @@ REGISTER_CLASS_TRAITS( LuaClass, new LuaClass(*pCopy) ) void *LuaBinding::GetUserdataFromGlobalTable( Lua *L, const char *szType, int iArg ) { - if( !GetGlobalTable(L, false) ) - luaL_error( L, "stale %s referenced (object used but no longer exists)", szType ); + GetGlobalTable( L ); lua_pushvalue( L, iArg ); lua_rawget( L, -2 ); @@ -195,12 +192,10 @@ LuaClass::~LuaClass() int iTop = lua_gettop( L ); /* If we're registered in the global table, unregister. */ - if( GetGlobalTable(L, false) ) - { - this->PushSelf( L ); - lua_pushnil( L ); - lua_rawset( L, -3 ); - } + GetGlobalTable( L ); + this->PushSelf( L ); + lua_pushnil( L ); + lua_rawset( L, -3 ); lua_settop( L, iTop );