diff --git a/stepmania/src/ActorUtil.cpp b/stepmania/src/ActorUtil.cpp index 5f2d5d33bc..a067e3bbbd 100644 --- a/stepmania/src/ActorUtil.cpp +++ b/stepmania/src/ActorUtil.cpp @@ -118,7 +118,7 @@ Actor* ActorUtil::LoadFromActorFile( const CString& sAniDir, const XNode* pNode CString expr; if( pNode->GetAttrValue("Condition",expr) ) { - if( !LUA->RunExpressionB(expr) ) + if( !LuaHelpers::RunExpressionB(expr) ) return NULL; } } diff --git a/stepmania/src/BGAnimation.cpp b/stepmania/src/BGAnimation.cpp index c0a8ab3202..7dfd5907d0 100644 --- a/stepmania/src/BGAnimation.cpp +++ b/stepmania/src/BGAnimation.cpp @@ -45,7 +45,7 @@ void BGAnimation::AddLayersFromAniDir( const CString &_sAniDir, const IniFile& i CString expr; if( ini.GetValue( "BGAnimation", "Condition", expr ) || ini.GetValue( "BGAnimation", "Cond", expr ) ) { - if( !LUA->RunExpressionB( expr ) ) + if( !LuaHelpers::RunExpressionB( expr ) ) return; } } @@ -73,7 +73,7 @@ void BGAnimation::AddLayersFromAniDir( const CString &_sAniDir, const IniFile& i CString expr; if( pKey->GetAttrValue("Condition",expr) ) { - if( !LUA->RunExpressionB( expr ) ) + if( !LuaHelpers::RunExpressionB( expr ) ) continue; } diff --git a/stepmania/src/BGAnimationLayer.cpp b/stepmania/src/BGAnimationLayer.cpp index 1fd9165eb7..e3f6b926a8 100644 --- a/stepmania/src/BGAnimationLayer.cpp +++ b/stepmania/src/BGAnimationLayer.cpp @@ -376,7 +376,7 @@ void BGAnimationLayer::LoadFromNode( const CString& sDir, const XNode* pNode ) CString expr; if( pNode->GetAttrValue("Cond",expr) || pNode->GetAttrValue("Condition",expr) ) { - if( !LUA->RunExpressionB(expr) ) + if( !LuaHelpers::RunExpressionB(expr) ) return; } } @@ -668,7 +668,7 @@ bool BGAnimationLayer::EarlyAbortDraw() return false; // TODO: Is it ok to evaluate this every frame? - if( !LUA->RunExpressionB(m_sDrawCond) ) + if( !LuaHelpers::RunExpressionB(m_sDrawCond) ) return true; return false; diff --git a/stepmania/src/LuaManager.cpp b/stepmania/src/LuaManager.cpp index e424ac3fe3..bd6cb5a5bc 100644 --- a/stepmania/src/LuaManager.cpp +++ b/stepmania/src/LuaManager.cpp @@ -300,10 +300,15 @@ bool LuaHelpers::RunScript( Lua *L, const CString &sExpression, const CString &s return true; } -bool LuaManager::RunExpressionB( const CString &str ) +bool LuaHelpers::RunExpressionB( const CString &str ) { + Lua *L = LUA->Get(); + if( !LuaHelpers::RunScript(L, "return " + str, "", 1) ) + { + LUA->Release(L); return false; + } /* Don't accept a function as a return value. */ if( lua_isfunction( L, -1 ) ) @@ -311,6 +316,7 @@ bool LuaManager::RunExpressionB( const CString &str ) bool result = !!lua_toboolean( L, -1 ); lua_pop( L, 1 ); + LUA->Release(L); return result; } diff --git a/stepmania/src/LuaManager.h b/stepmania/src/LuaManager.h index 3594503e73..531067adca 100644 --- a/stepmania/src/LuaManager.h +++ b/stepmania/src/LuaManager.h @@ -60,7 +60,6 @@ public: void ResetState(); /* Run an expression in the global environment, returning the given type. */ - bool RunExpressionB( const CString &str ); float RunExpressionF( const CString &str ); int RunExpressionI( const CString &str ); bool RunExpressionS( const CString &str, CString &sOut ); @@ -104,6 +103,9 @@ namespace LuaHelpers /* Read the table at the top of the stack back into a vector. */ void ReadArrayFromTableB( Lua *L, vector &aOut ); + /* Run an expression in the global environment, returning the given type. */ + bool RunExpressionB( const CString &str ); + template void ReadArrayFromTable( vector &aOut, lua_State *L ) { diff --git a/stepmania/src/ThemeManager.cpp b/stepmania/src/ThemeManager.cpp index 6473850a7e..b075ea6ef9 100644 --- a/stepmania/src/ThemeManager.cpp +++ b/stepmania/src/ThemeManager.cpp @@ -739,7 +739,7 @@ bool ThemeManager::GetMetricB( const CString &sClassName, const CString &sValueN LUA->PrepareExpression( sValue ); - return LUA->RunExpressionB( sValue ); + return LuaHelpers::RunExpressionB( sValue ); } RageColor ThemeManager::GetMetricC( const CString &sClassName, const CString &sValueName )