From a183541eedc2712481b67cd516f54e06c307be22 Mon Sep 17 00:00:00 2001 From: Steve Checkoway Date: Sun, 15 Oct 2006 03:16:06 +0000 Subject: [PATCH] Use FOREACH_LUATABLE. --- stepmania/src/LuaManager.cpp | 26 +++++--------------------- stepmania/src/XmlFileUtil.cpp | 5 +---- 2 files changed, 6 insertions(+), 25 deletions(-) diff --git a/stepmania/src/LuaManager.cpp b/stepmania/src/LuaManager.cpp index a32a09d2c0..e7e610b903 100644 --- a/stepmania/src/LuaManager.cpp +++ b/stepmania/src/LuaManager.cpp @@ -297,7 +297,7 @@ namespace RString m_sBaseName; vector m_vMethods; }; -} +} XNode *LuaHelpers::GetLuaInformation() { @@ -318,19 +318,11 @@ XNode *LuaHelpers::GetLuaInformation() map mConstants; map mStringConstants; map > mEnums; - - lua_pushnil( L ); // initial key - while( lua_next(L, LUA_GLOBALSINDEX) ) + + FOREACH_LUATABLE( L, LUA_GLOBALSINDEX ) { - // key is at -2, value is at -1 - - /* Tricky. FromStack() calls lua_tolstring() which changes the underlying cell - * if it is not a string. This confuses lua_next(). Copy the value first. - * http://www.lua.org/manual/5.1/manual.html#lua_tolstring */ - RString sKey; - lua_pushvalue( L, -2 ); LuaHelpers::Pop( L, sKey ); switch( lua_type(L, -1) ) @@ -342,10 +334,7 @@ XNode *LuaHelpers::GetLuaInformation() const char *name = lua_tostring( L, -1 ); if( !name ) - { - lua_pop( L, 1 ); // pop nil break; - } LClass &c = mClasses[name]; lua_pop( L, 1 ); // pop name @@ -360,14 +349,10 @@ XNode *LuaHelpers::GetLuaInformation() } // Get methods. - lua_pushnil( L ); // initial key - while( lua_next(L, -2) ) + FOREACH_LUATABLE( L, -1 ) { - // Again, be careful about reading the key as a string. - lua_pop( L, 1 ); // pop value - lua_pushvalue( L, -1 ); RString sMethod; - if( LuaHelpers::Pop(L, sMethod) ) + if( LuaHelpers::FromStack(L, sMethod, -1) ) c.m_vMethods.push_back( sMethod ); } sort( c.m_vMethods.begin(), c.m_vMethods.end() ); @@ -404,7 +389,6 @@ XNode *LuaHelpers::GetLuaInformation() vFunctions.push_back( sKey ); break; } - lua_pop( L, 1 ); // pop value } sort( vFunctions.begin(), vFunctions.end() ); diff --git a/stepmania/src/XmlFileUtil.cpp b/stepmania/src/XmlFileUtil.cpp index 627de5840f..e2a97305b2 100644 --- a/stepmania/src/XmlFileUtil.cpp +++ b/stepmania/src/XmlFileUtil.cpp @@ -646,10 +646,8 @@ namespace /* Iterate over the table, pulling out attributes and tables to process. */ map NodesToAdd; - lua_pushnil( L ); - while( lua_next(L, -2) ) + FOREACH_LUATABLE( L, -1 ) { - lua_pushvalue( L, -2 ); RString sName; LuaHelpers::Pop( L, sName ); @@ -665,7 +663,6 @@ namespace pValue->SetValueFromStack( L ); pNode->AppendAttrFrom( sName, pValue ); } - lua_pop( L, 1 ); // pop nil /* Recursively process tables. */ FOREACHM( RString, LuaReference, NodesToAdd, t )