diff --git a/stepmania/src/ActorCommands.cpp b/stepmania/src/ActorCommands.cpp index 959d97ec9d..f6baadcc36 100644 --- a/stepmania/src/ActorCommands.cpp +++ b/stepmania/src/ActorCommands.cpp @@ -17,7 +17,9 @@ void IncorrectActorParametersWarning( const ParsedCommand &command, int iMaxInde void ParsedCommandToken::Set( const CString &sParam ) { s = sParam; - f = Lua::RunExpressionF( sParam ); + CString s = sParam; + Lua::PrepareExpression( s ); // strip invalid chars + f = Lua::RunExpressionF( s ); bColorIsValid = c.FromString( sParam ); } diff --git a/stepmania/src/LuaHelpers.cpp b/stepmania/src/LuaHelpers.cpp index 772548252f..1bb4d53c35 100644 --- a/stepmania/src/LuaHelpers.cpp +++ b/stepmania/src/LuaHelpers.cpp @@ -184,6 +184,17 @@ void Lua::UpdateGlobals() lua_setglobal( L, "SCREEN_CENTER_Y" ); } +void Lua::PrepareExpression( CString &sInOut ) +{ + // HACK: Many metrics have "//" comments that Lua fails to parse. + // Replace them with Lua-style comments. + sInOut.Replace( "//", "--" ); + + // Remove leading +, eg. "+50"; Lua doesn't handle that. + if( sInOut.size() >= 1 && sInOut[0] == '+' ) + sInOut.erase( 0, 1 ); +} + void RunExpression( const CString &str ) { LoadFromString( L, "return " + str ); diff --git a/stepmania/src/LuaHelpers.h b/stepmania/src/LuaHelpers.h index 7860c2e30c..bafc053c42 100644 --- a/stepmania/src/LuaHelpers.h +++ b/stepmania/src/LuaHelpers.h @@ -4,6 +4,7 @@ struct lua_State; namespace Lua { + void PrepareExpression( CString &sInOut ); // strip "//" comments and "+" bool RunExpressionB( const CString &str ); float RunExpressionF( const CString &str ); diff --git a/stepmania/src/ThemeManager.cpp b/stepmania/src/ThemeManager.cpp index be7aa61b30..e9c1983fce 100644 --- a/stepmania/src/ThemeManager.cpp +++ b/stepmania/src/ThemeManager.cpp @@ -615,13 +615,8 @@ int ThemeManager::GetMetricI( CString sClassName, CString sValueName ) float ThemeManager::GetMetricF( CString sClassName, CString sValueName ) { CString str = GetMetricRaw( sClassName,sValueName ); - // HACK: Many metrics have "//" comments that Lua fails to parse. - // Replace them with Lua-style comments. - str.Replace( "//", "--" ); - // Remove leading +, eg. "+50"; Lua doesn't handle that. - if( str.size() >= 1 && str[0] == '+' ) - str.erase( 0, 1 ); + Lua::PrepareExpression( str ); return Lua::RunExpressionF( str ); } @@ -634,9 +629,9 @@ bool ThemeManager::GetMetricB( CString sClassName, CString sValueName ) return false; /* optimization */ if( str == "1" ) return true; /* optimization */ - // HACK: Many metrics have "//" comments that Lua fails to parse. - // Replace them with Lua-style comments. - str.Replace( "//", "--" ); + + Lua::PrepareExpression( str ); + return Lua::RunExpressionB( str ); }