evaluate TargetNumber as a Lua expression
This commit is contained in:
@@ -376,7 +376,7 @@ void BGAnimationLayer::LoadFromNode( const CString& sDir, const XNode* pNode )
|
|||||||
CString expr;
|
CString expr;
|
||||||
if( pNode->GetAttrValue("Cond",expr) || pNode->GetAttrValue("Condition",expr) )
|
if( pNode->GetAttrValue("Cond",expr) || pNode->GetAttrValue("Condition",expr) )
|
||||||
{
|
{
|
||||||
if( !LUA->RunExpressionB( expr ) )
|
if( !LUA->RunExpressionB(expr) )
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -672,7 +672,8 @@ bool BGAnimationLayer::EarlyAbortDraw()
|
|||||||
if( m_sDrawCond.empty() )
|
if( m_sDrawCond.empty() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if( !LUA->RunExpressionB( m_sDrawCond ) )
|
// TODO: Is it ok to evaluate this every frame?
|
||||||
|
if( !LUA->RunExpressionB(m_sDrawCond) )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ Command::Arg Command::GetArg( unsigned index ) const
|
|||||||
Command::Arg::operator CString ()
|
Command::Arg::operator CString ()
|
||||||
{
|
{
|
||||||
CString sValue = s;
|
CString sValue = s;
|
||||||
LUA->RunAtExpression( sValue );
|
LUA->RunAtExpressionS( sValue );
|
||||||
return sValue;
|
return sValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -364,7 +364,7 @@ bool LuaManager::RunExpressionS( const CString &str, CString &sOut )
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LuaManager::RunAtExpression( CString &sStr )
|
bool LuaManager::RunAtExpressionS( CString &sStr )
|
||||||
{
|
{
|
||||||
if( sStr.size() == 0 || sStr[0] != '@' )
|
if( sStr.size() == 0 || sStr[0] != '@' )
|
||||||
return false;
|
return false;
|
||||||
@@ -378,6 +378,21 @@ bool LuaManager::RunAtExpression( CString &sStr )
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float LuaManager::RunAtExpressionF( const CString &_sStr )
|
||||||
|
{
|
||||||
|
if( _sStr.size() == 0 || _sStr[0] != '@' )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
CString sStr = _sStr;
|
||||||
|
|
||||||
|
/* Erase "@". */
|
||||||
|
sStr.erase( 0, 1 );
|
||||||
|
|
||||||
|
CString sOut;
|
||||||
|
RunExpressionS( sStr, sOut );
|
||||||
|
return atof( sOut );
|
||||||
|
}
|
||||||
|
|
||||||
void LuaManager::Fail( const CString &err )
|
void LuaManager::Fail( const CString &err )
|
||||||
{
|
{
|
||||||
lua_pushstring( L, err );
|
lua_pushstring( L, err );
|
||||||
|
|||||||
@@ -30,7 +30,8 @@ public:
|
|||||||
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. */
|
/* If sStr begins with @, evaluate the rest as an expression and store the result over sStr. */
|
||||||
bool RunAtExpression( CString &sStr );
|
bool RunAtExpressionS( CString &sStr );
|
||||||
|
float RunAtExpressionF( const CString &sStr );
|
||||||
|
|
||||||
void Fail( const CString &err );
|
void Fail( const CString &err );
|
||||||
|
|
||||||
|
|||||||
@@ -550,7 +550,7 @@ public:
|
|||||||
Luna<T>::Register( L );
|
Luna<T>::Register( L );
|
||||||
|
|
||||||
// Add global singleton if constructed already. If it's not constructed yet,
|
// Add global singleton if constructed already. If it's not constructed yet,
|
||||||
// then we'll register it later when we reload the theme just before
|
// then we'll register it later when we reinit Lua just before
|
||||||
// initializing the display.
|
// initializing the display.
|
||||||
if( PROFILEMAN )
|
if( PROFILEMAN )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -26,9 +26,12 @@ void RollingNumbers::LoadFromNode( const CString& sDir, const XNode* pNode )
|
|||||||
pNode->GetAttrValue( "Format", m_sFormat );
|
pNode->GetAttrValue( "Format", m_sFormat );
|
||||||
pNode->GetAttrValue( "ApproachSeconds", m_fApproachSeconds );
|
pNode->GetAttrValue( "ApproachSeconds", m_fApproachSeconds );
|
||||||
|
|
||||||
float fTargetNumber;
|
CString sTargetNumber;
|
||||||
if( pNode->GetAttrValue( "TargetNumber", fTargetNumber ) )
|
if( pNode->GetAttrValue( "TargetNumber", sTargetNumber ) )
|
||||||
|
{
|
||||||
|
float fTargetNumber = LUA->RunExpressionF(sTargetNumber);
|
||||||
SetTargetNumber( fTargetNumber );
|
SetTargetNumber( fTargetNumber );
|
||||||
|
}
|
||||||
|
|
||||||
UpdateText();
|
UpdateText();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -677,7 +677,7 @@ 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( LUA->RunAtExpression( sText ) )
|
if( LUA->RunAtExpressionS( sText ) )
|
||||||
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.
|
||||||
|
|||||||
Reference in New Issue
Block a user