always leave iReturnValues on the stack, even on error, so error handling can just log the error and continue as if nil was actually returned

This commit is contained in:
Glenn Maynard
2006-09-23 02:44:35 +00:00
parent c9045a920c
commit 0d05ebd9b5
2 changed files with 8 additions and 7 deletions
+5 -5
View File
@@ -509,6 +509,8 @@ bool LuaHelpers::RunScript( Lua *L, const RString &sScript, const RString &sName
if( ret )
{
LuaHelpers::Pop( L, sError );
for( int i = 0; i < iReturnValues; ++i )
lua_pushnil( L );
return false;
}
}
@@ -519,6 +521,8 @@ bool LuaHelpers::RunScript( Lua *L, const RString &sScript, const RString &sName
if( ret )
{
LuaHelpers::Pop( L, sError );
for( int i = 0; i < iReturnValues; ++i )
lua_pushnil( L );
return false;
}
}
@@ -544,11 +548,7 @@ bool LuaHelpers::RunExpression( Lua *L, const RString &sExpression, const RStrin
{
RString sFullExpression = "return " + sExpression;
bool bSuccess = LuaHelpers::RunScript( L, sFullExpression, sName, 1 );
if( !bSuccess )
lua_pushnil( L );
return bSuccess;
return LuaHelpers::RunScript( L, sFullExpression, sName, 1 );
}
bool LuaHelpers::RunExpressionB( const RString &str )
+3 -2
View File
@@ -48,8 +48,9 @@ private:
namespace LuaHelpers
{
/* Run a script with the given name. Return values are left on the Lua stack.
* Returns false on error, with sError set. */
/* Run a script with the given name. The given number of return values are left on
* the Lua stack. On error, nils are left on the stack, sError is set and
* false is returned. */
bool RunScript( Lua *L, const RString &sScript, const RString &sName, RString &sError, int iReturnValues = 0 );
/* Convenience: run a script with one return value, displaying an error on failure.