fix script loading
move @expression evaluation into LuaManager (LuaManager::RunAtExpression) evaluate string command parameters
This commit is contained in:
@@ -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 ()
|
||||
|
||||
@@ -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 );
|
||||
|
||||
@@ -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 ); }
|
||||
|
||||
@@ -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<Theme>::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"
|
||||
|
||||
Reference in New Issue
Block a user