Revert "Improve handling of errors in lua functions and speed up calls. (#1427)"

This reverts commit f10e3ae36a.

(it was a joke PR, do not fear)
This commit is contained in:
Colby Klein
2017-04-04 17:21:55 -07:00
parent f10e3ae36a
commit b4e02821e8
21 changed files with 86 additions and 38 deletions
+23 -6
View File
@@ -829,19 +829,36 @@ void LuaHelpers::ReportScriptErrorFmt(const char *fmt, ...)
ReportScriptError(Buff);
}
bool LuaHelpers::RunScriptOnStack(Lua *L, int Args, int ReturnValues)
bool LuaHelpers::RunScriptOnStack( Lua *L, RString &Error, int Args, int ReturnValues, bool ReportError )
{
lua_pushcfunction( L, GetLuaStack );
// move the error function above the function and params
int ErrFunc = lua_gettop(L) - Args - 1;
lua_insert( L, ErrFunc );
// evaluate
int ret = lua_pcall(L, Args, ReturnValues, 0);
int ret = lua_pcall( L, Args, ReturnValues, ErrFunc );
if( ret )
{
lua_pop(L, 1);
for( int i = 0; i < ReturnValues; ++i )
if(ReportError)
{
lua_pushnil( L );
RString lerror;
LuaHelpers::Pop( L, lerror );
Error+= lerror;
ReportScriptError(Error);
}
else
{
LuaHelpers::Pop( L, Error );
}
lua_remove( L, ErrFunc );
for( int i = 0; i < ReturnValues; ++i )
lua_pushnil( L );
return false;
}
lua_remove( L, ErrFunc );
return true;
}
@@ -864,7 +881,7 @@ bool LuaHelpers::RunScript( Lua *L, const RString &Script, const RString &Name,
// move the function above the params
lua_insert( L, lua_gettop(L) - Args );
return LuaHelpers::RunScriptOnStack(L, Args, ReturnValues);
return LuaHelpers::RunScriptOnStack( L, Error, Args, ReturnValues, ReportError );
}
bool LuaHelpers::RunExpression( Lua *L, const RString &sExpression, const RString &sName )