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 ()
|
Command::Arg::operator CString ()
|
||||||
{
|
{
|
||||||
return s;
|
CString sValue = s;
|
||||||
|
LUA->RunAtExpression( sValue );
|
||||||
|
return sValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Command::Arg::operator float ()
|
Command::Arg::operator float ()
|
||||||
|
|||||||
@@ -302,6 +302,20 @@ bool LuaManager::RunExpressionS( const CString &str, CString &sOut )
|
|||||||
return true;
|
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 )
|
void LuaManager::Fail( const CString &err )
|
||||||
{
|
{
|
||||||
lua_pushstring( L, err );
|
lua_pushstring( L, err );
|
||||||
|
|||||||
@@ -23,6 +23,9 @@ public:
|
|||||||
float RunExpressionF( const CString &str );
|
float RunExpressionF( const CString &str );
|
||||||
bool RunExpressionS( const CString &str, CString &sOut );
|
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 Fail( const CString &err );
|
||||||
|
|
||||||
void SetGlobal( const CString &sName, int val ) { PushStack(val); SetGlobal( sName ); }
|
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
|
/* Run all script files in Lua for all themes. Start from the deepest fallback
|
||||||
* theme and work outwards. */
|
* theme and work outwards. */
|
||||||
deque<Theme>::const_iterator iter = g_vThemes.end();
|
deque<Theme>::const_iterator iter = g_vThemes.end();
|
||||||
--iter;
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
--iter;
|
||||||
const CString &sThemeDir = GetThemeDirFromName( iter->sThemeName );
|
const CString &sThemeDir = GetThemeDirFromName( iter->sThemeName );
|
||||||
CStringArray asElementPaths;
|
CStringArray asElementPaths;
|
||||||
GetDirListing( sThemeDir + "Scripts/*.lua", asElementPaths, false, true );
|
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
|
/* 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) */
|
* other filtering. (XXX: maybe we should still do font aliases) */
|
||||||
if( sText.size() >= 1 && sText[0] == '@' )
|
if( LUA->RunAtExpression( sText ) )
|
||||||
{
|
|
||||||
/* Erase "@". */
|
|
||||||
sText.erase( 0, 1 );
|
|
||||||
|
|
||||||
CString sOut;
|
|
||||||
LUA->RunExpressionS( sText, sOut );
|
|
||||||
sText = sOut;
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
// "::" means newline since you can't use line breaks in an ini file.
|
// "::" 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"
|
// 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