Fix crash if lua_tostring() returns NULL.

This commit is contained in:
Steve Checkoway
2006-09-21 09:42:08 +00:00
parent 95faef1776
commit 1598deda7f
2 changed files with 16 additions and 6 deletions
+15 -4
View File
@@ -343,7 +343,9 @@ XNode *LuaManager::GetLuaInformation() const
while( lua_next(L, -2) ) while( lua_next(L, -2) )
{ {
lua_pop( L, 1 ); // pop value lua_pop( L, 1 ); // pop value
c.m_vMethods.push_back( lua_tostring(L, -1) ); RString sKey;
if( LuaHelpers::FromStack(sKey, -1, L) )
c.m_vMethods.push_back( sKey );
} }
sort( c.m_vMethods.begin(), c.m_vMethods.end() ); sort( c.m_vMethods.begin(), c.m_vMethods.end() );
} }
@@ -374,7 +376,11 @@ XNode *LuaManager::GetLuaInformation() const
const char *type = lua_tostring( L, -1 ); const char *type = lua_tostring( L, -1 );
if( type ) if( type )
mSingletons[lua_tostring(L, -6)] = type; {
RString sKey;
if( LuaHelpers::FromStack(sKey, -6, L) )
mSingletons[sKey] = type;
}
lua_pop( L, 4 ); // pop type, method metatable, method table, and metatable lua_pop( L, 4 ); // pop type, method metatable, method table, and metatable
break; break;
} }
@@ -384,7 +390,11 @@ XNode *LuaManager::GetLuaInformation() const
float fNum = float( lua_tonumber(L, -1) ); float fNum = float( lua_tonumber(L, -1) );
if( fNum == truncf(fNum) ) if( fNum == truncf(fNum) )
mConstants[lua_tostring(L, -2)] = int( fNum ); {
RString sKey;
if( LuaHelpers::FromStack(sKey, -2, L) )
mConstants[sKey] = int( fNum );
}
break; break;
} }
} }
@@ -625,7 +635,8 @@ RString GetLuaBindingType( Lua *L, int iArgNo )
int iMetatable = lua_gettop( L ); int iMetatable = lua_gettop( L );
lua_pushstring( L, "type" ); lua_pushstring( L, "type" );
lua_rawget( L, iMetatable ); lua_rawget( L, iMetatable );
RString sActualType = lua_tostring( L, -1 ); RString sActualType;
LuaHelpers::FromStack( sActualType, -1, L );
lua_settop( L, iTop ); lua_settop( L, iTop );
return sActualType; return sActualType;
+1 -2
View File
@@ -169,8 +169,7 @@ void PercentageDisplay::Refresh()
ASSERT( !lua_isnil(L, -1) ); ASSERT( !lua_isnil(L, -1) );
LuaHelpers::Push( fPercentDancePoints, L ); LuaHelpers::Push( fPercentDancePoints, L );
lua_call( L, 1, 1 ); // 1 args, 1 result lua_call( L, 1, 1 ); // 1 args, 1 result
sNumToDisplay = lua_tostring( L, -1 ); LuaHelpers::Pop( sNumToDisplay, L );
lua_pop( L, 1 );
LUA->Release(L); LUA->Release(L);
// HACK: Use the last frame in the numbers texture as '-' // HACK: Use the last frame in the numbers texture as '-'