diff --git a/stepmania/src/Command.cpp b/stepmania/src/Command.cpp index 5ce62c01ed..048cc30d87 100644 --- a/stepmania/src/Command.cpp +++ b/stepmania/src/Command.cpp @@ -33,7 +33,9 @@ Command::Arg Command::GetArg( unsigned index ) const Command::Arg::operator CString () { - return s; + CString sValue = s; + LUA->RunAtExpression( sValue ); + return sValue; } Command::Arg::operator float () diff --git a/stepmania/src/LuaHelpers.cpp b/stepmania/src/LuaHelpers.cpp index e5f3294059..fa352a2079 100644 --- a/stepmania/src/LuaHelpers.cpp +++ b/stepmania/src/LuaHelpers.cpp @@ -302,6 +302,20 @@ bool LuaManager::RunExpressionS( const CString &str, CString &sOut ) return true; } +bool LuaManager::RunAtExpression( CString &sStr ) +{ + if( sStr.size() == 0 || sStr[0] != '@' ) + return false; + + /* Erase "@". */ + sStr.erase( 0, 1 ); + + CString sOut; + RunExpressionS( sStr, sOut ); + sStr = sOut; + return true; +} + void LuaManager::Fail( const CString &err ) { lua_pushstring( L, err ); diff --git a/stepmania/src/LuaHelpers.h b/stepmania/src/LuaHelpers.h index c7ed4f78de..ae02701698 100644 --- a/stepmania/src/LuaHelpers.h +++ b/stepmania/src/LuaHelpers.h @@ -23,6 +23,9 @@ public: float RunExpressionF( const CString &str ); bool RunExpressionS( const CString &str, CString &sOut ); + /* If sStr begins with @, evaluate the rest as an expression and store the result over sStr. */ + bool RunAtExpression( CString &sStr ); + void Fail( const CString &err ); void SetGlobal( const CString &sName, int val ) { PushStack(val); SetGlobal( sName ); } diff --git a/stepmania/src/ThemeManager.cpp b/stepmania/src/ThemeManager.cpp index 40e611f7e4..74299395e3 100644 --- a/stepmania/src/ThemeManager.cpp +++ b/stepmania/src/ThemeManager.cpp @@ -294,9 +294,9 @@ void ThemeManager::UpdateLuaGlobals() /* Run all script files in Lua for all themes. Start from the deepest fallback * theme and work outwards. */ deque::const_iterator iter = g_vThemes.end(); - --iter; do { + --iter; const CString &sThemeDir = GetThemeDirFromName( iter->sThemeName ); CStringArray asElementPaths; GetDirListing( sThemeDir + "Scripts/*.lua", asElementPaths, false, true ); @@ -669,16 +669,8 @@ void ThemeManager::EvaluateString( CString &sText ) { /* If the string begins with an @, treat it as a raw Lua expression, and don't do any * other filtering. (XXX: maybe we should still do font aliases) */ - if( sText.size() >= 1 && sText[0] == '@' ) - { - /* Erase "@". */ - sText.erase( 0, 1 ); - - CString sOut; - LUA->RunExpressionS( sText, sOut ); - sText = sOut; + if( LUA->RunAtExpression( sText ) ) return; - } // "::" means newline since you can't use line breaks in an ini file. // XXX: this makes it impossible to put a colon at the end of a line, eg: "Color:\nRed"