Use FOREACH_LUATABLE.

This commit is contained in:
Steve Checkoway
2006-10-15 03:16:06 +00:00
parent 943ba7e0fa
commit a183541eed
2 changed files with 6 additions and 25 deletions
+3 -19
View File
@@ -319,18 +319,10 @@ XNode *LuaHelpers::GetLuaInformation()
map<RString, RString> mStringConstants; map<RString, RString> mStringConstants;
map<RString, vector<RString> > mEnums; map<RString, vector<RString> > mEnums;
lua_pushnil( L ); // initial key FOREACH_LUATABLE( L, LUA_GLOBALSINDEX )
while( lua_next(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; RString sKey;
lua_pushvalue( L, -2 );
LuaHelpers::Pop( L, sKey ); LuaHelpers::Pop( L, sKey );
switch( lua_type(L, -1) ) switch( lua_type(L, -1) )
@@ -342,10 +334,7 @@ XNode *LuaHelpers::GetLuaInformation()
const char *name = lua_tostring( L, -1 ); const char *name = lua_tostring( L, -1 );
if( !name ) if( !name )
{
lua_pop( L, 1 ); // pop nil
break; break;
}
LClass &c = mClasses[name]; LClass &c = mClasses[name];
lua_pop( L, 1 ); // pop name lua_pop( L, 1 ); // pop name
@@ -360,14 +349,10 @@ XNode *LuaHelpers::GetLuaInformation()
} }
// Get methods. // Get methods.
lua_pushnil( L ); // initial key FOREACH_LUATABLE( L, -1 )
while( lua_next(L, -2) )
{ {
// Again, be careful about reading the key as a string.
lua_pop( L, 1 ); // pop value
lua_pushvalue( L, -1 );
RString sMethod; RString sMethod;
if( LuaHelpers::Pop(L, sMethod) ) if( LuaHelpers::FromStack(L, sMethod, -1) )
c.m_vMethods.push_back( sMethod ); c.m_vMethods.push_back( sMethod );
} }
sort( c.m_vMethods.begin(), c.m_vMethods.end() ); sort( c.m_vMethods.begin(), c.m_vMethods.end() );
@@ -404,7 +389,6 @@ XNode *LuaHelpers::GetLuaInformation()
vFunctions.push_back( sKey ); vFunctions.push_back( sKey );
break; break;
} }
lua_pop( L, 1 ); // pop value
} }
sort( vFunctions.begin(), vFunctions.end() ); sort( vFunctions.begin(), vFunctions.end() );
+1 -4
View File
@@ -646,10 +646,8 @@ namespace
/* Iterate over the table, pulling out attributes and tables to process. */ /* Iterate over the table, pulling out attributes and tables to process. */
map<RString, LuaReference> NodesToAdd; map<RString, LuaReference> NodesToAdd;
lua_pushnil( L ); FOREACH_LUATABLE( L, -1 )
while( lua_next(L, -2) )
{ {
lua_pushvalue( L, -2 );
RString sName; RString sName;
LuaHelpers::Pop( L, sName ); LuaHelpers::Pop( L, sName );
@@ -665,7 +663,6 @@ namespace
pValue->SetValueFromStack( L ); pValue->SetValueFromStack( L );
pNode->AppendAttrFrom( sName, pValue ); pNode->AppendAttrFrom( sName, pValue );
} }
lua_pop( L, 1 ); // pop nil
/* Recursively process tables. */ /* Recursively process tables. */
FOREACHM( RString, LuaReference, NodesToAdd, t ) FOREACHM( RString, LuaReference, NodesToAdd, t )