From dd3b2275622623ff9dbbb2ed386221fa6713a419 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Thu, 16 Jun 2005 06:37:45 +0000 Subject: [PATCH] LuaHelpers::RunExpressionI, LuaHelpers::RunExpressionS --- stepmania/src/LuaManager.cpp | 11 ++++++++--- stepmania/src/LuaManager.h | 6 ++---- stepmania/src/ScoreDisplayAliveTime.cpp | 2 +- stepmania/src/ScoreDisplayCalories.cpp | 2 +- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/stepmania/src/LuaManager.cpp b/stepmania/src/LuaManager.cpp index 36b7cd2b8c..ce0b28c711 100644 --- a/stepmania/src/LuaManager.cpp +++ b/stepmania/src/LuaManager.cpp @@ -341,15 +341,19 @@ float LuaHelpers::RunExpressionF( const CString &str ) return result; } -int LuaManager::RunExpressionI( const CString &str ) +int LuaHelpers::RunExpressionI( const CString &str ) { return (int) LuaHelpers::RunExpressionF(str); } -bool LuaManager::RunExpressionS( const CString &str, CString &sOut ) +bool LuaHelpers::RunExpressionS( const CString &str, CString &sOut ) { + 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 ) ) @@ -358,6 +362,7 @@ bool LuaManager::RunExpressionS( const CString &str, CString &sOut ) sOut = lua_tostring( L, -1 ); lua_pop( L, 1 ); + LUA->Release(L); return true; } @@ -370,7 +375,7 @@ bool LuaManager::RunAtExpressionS( CString &sStr ) sStr.erase( 0, 1 ); CString sOut; - RunExpressionS( sStr, sOut ); + LuaHelpers::RunExpressionS( sStr, sOut ); sStr = sOut; return true; } diff --git a/stepmania/src/LuaManager.h b/stepmania/src/LuaManager.h index c3a8146767..a07bd54735 100644 --- a/stepmania/src/LuaManager.h +++ b/stepmania/src/LuaManager.h @@ -59,10 +59,6 @@ public: /* Reset the environment, freeing any globals left over by previously executed scripts. */ void ResetState(); - /* Run an expression in the global environment, returning the given type. */ - int RunExpressionI( 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 RunAtExpressionS( CString &sStr ); @@ -105,6 +101,8 @@ namespace LuaHelpers /* 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 ); template void ReadArrayFromTable( vector &aOut, lua_State *L ) diff --git a/stepmania/src/ScoreDisplayAliveTime.cpp b/stepmania/src/ScoreDisplayAliveTime.cpp index 762c5b2b5f..db08c7b492 100644 --- a/stepmania/src/ScoreDisplayAliveTime.cpp +++ b/stepmania/src/ScoreDisplayAliveTime.cpp @@ -30,7 +30,7 @@ void ScoreDisplayAliveTime::LoadFromNode( const CString& sDir, const XNode* pNod CString sPlayerNumber; bool b = pNode->GetAttrValue( "PlayerNumber", sPlayerNumber ); ASSERT( b ); - m_PlayerNumber = (PlayerNumber)LUA->RunExpressionI(sPlayerNumber); + m_PlayerNumber = (PlayerNumber) LuaHelpers::RunExpressionI(sPlayerNumber); } } diff --git a/stepmania/src/ScoreDisplayCalories.cpp b/stepmania/src/ScoreDisplayCalories.cpp index b1dfde2b77..1e51b22de6 100644 --- a/stepmania/src/ScoreDisplayCalories.cpp +++ b/stepmania/src/ScoreDisplayCalories.cpp @@ -32,7 +32,7 @@ void ScoreDisplayCalories::LoadFromNode( const CString& sDir, const XNode* pNode CString sPlayerNumber; bool b = pNode->GetAttrValue( "PlayerNumber", sPlayerNumber ); ASSERT( b ); - m_PlayerNumber = (PlayerNumber)LUA->RunExpressionI(sPlayerNumber); + m_PlayerNumber = (PlayerNumber) LuaHelpers::RunExpressionI(sPlayerNumber); } m_sMessageOnStep = ssprintf("StepP%d",m_PlayerNumber+1);