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:
@@ -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 )
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user