Moved all sanity checking for OptionRowHandlerLua to a separate function so that a malformed row does not crash StepMania, and instead prints an error to the log file, and creates a row that does nothing. Added AllowAnything arg to CheckEnum.

This commit is contained in:
Kyzentun
2014-06-25 12:08:57 -06:00
parent d472d28490
commit dcf819d297
6 changed files with 224 additions and 96 deletions
+14 -1
View File
@@ -2,8 +2,9 @@
#include "EnumHelper.h"
#include "LuaManager.h"
#include "RageUtil.h"
#include "RageLog.h"
int CheckEnum( lua_State *L, LuaReference &table, int iPos, int iInvalid, const char *szType, bool bAllowInvalid )
int CheckEnum( lua_State *L, LuaReference &table, int iPos, int iInvalid, const char *szType, bool bAllowInvalid, bool bAllowAnything )
{
luaL_checkany( L, iPos );
@@ -61,6 +62,18 @@ int CheckEnum( lua_State *L, LuaReference &table, int iPos, int iInvalid, const
LuaHelpers::Pop( L, sGot );
}
LuaHelpers::Push( L, ssprintf("Expected %s; got %s", szType, sGot.c_str() ) );
// There are a couple places where CheckEnum is used outside of a
// function called from lua. If we use lua_error from one of them,
// StepMania crashes out completely. bAllowAnything allows those places
// to avoid crashing over theme mistakes.
if(bAllowAnything)
{
RString errmsg;
LuaHelpers::Pop(L, errmsg);
LOG->Warn(errmsg.c_str());
lua_pop(L, 2);
return iInvalid;
}
lua_error( L );
}
int iRet = lua_tointeger( L, -1 );