From 9a50b17b9df0bf3e49552bae55da0f15ca1f4ca6 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Thu, 16 Jun 2005 22:17:45 +0000 Subject: [PATCH] LuaHelpers::RunAtExpressionS LuaManager::ResetState, LuaHelpers::RunScriptFile locking --- stepmania/src/ActorUtil.cpp | 2 +- stepmania/src/Command.cpp | 2 +- stepmania/src/LuaManager.cpp | 6 +++++- stepmania/src/LuaManager.h | 6 +++--- stepmania/src/ThemeManager.cpp | 2 +- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/stepmania/src/ActorUtil.cpp b/stepmania/src/ActorUtil.cpp index a067e3bbbd..81fe8b7c0b 100644 --- a/stepmania/src/ActorUtil.cpp +++ b/stepmania/src/ActorUtil.cpp @@ -142,7 +142,7 @@ Actor* ActorUtil::LoadFromActorFile( const CString& sAniDir, const XNode* pNode } - LUA->RunAtExpressionS( sFile ); + LuaHelpers::RunAtExpressionS( sFile ); bool bIsAbsolutePath = sFile.Left(1) == "/"; FixSlashesInPlace( sFile ); diff --git a/stepmania/src/Command.cpp b/stepmania/src/Command.cpp index a3afd477ee..7f5fab5dd5 100644 --- a/stepmania/src/Command.cpp +++ b/stepmania/src/Command.cpp @@ -34,7 +34,7 @@ Command::Arg Command::GetArg( unsigned index ) const Command::Arg::operator CString () { CString sValue = s; - LUA->RunAtExpressionS( sValue ); + LuaHelpers::RunAtExpressionS( sValue ); return sValue; } diff --git a/stepmania/src/LuaManager.cpp b/stepmania/src/LuaManager.cpp index 05af0a1345..45eb30a0f9 100644 --- a/stepmania/src/LuaManager.cpp +++ b/stepmania/src/LuaManager.cpp @@ -192,6 +192,8 @@ void LuaManager::RegisterTypes() void LuaManager::ResetState() { + m_pLock->Lock(); + if( L != NULL ) { LuaReference::BeforeResetAll(); @@ -213,6 +215,8 @@ void LuaManager::ResetState() RegisterTypes(); LuaReference::AfterResetAll(); + + m_pLock->Unlock(); } void LuaManager::PrepareExpression( CString &sInOut ) @@ -370,7 +374,7 @@ bool LuaHelpers::RunExpressionS( const CString &str, CString &sOut ) return true; } -bool LuaManager::RunAtExpressionS( CString &sStr ) +bool LuaHelpers::RunAtExpressionS( CString &sStr ) { if( sStr.size() == 0 || sStr[0] != '@' ) return false; diff --git a/stepmania/src/LuaManager.h b/stepmania/src/LuaManager.h index 0a31d3a6fd..adb17124c1 100644 --- a/stepmania/src/LuaManager.h +++ b/stepmania/src/LuaManager.h @@ -59,9 +59,6 @@ public: /* Reset the environment, freeing any globals left over by previously executed scripts. */ void ResetState(); - /* If sStr begins with @, evaluate the rest as an expression and store the result over sStr. */ - bool RunAtExpressionS( CString &sStr ); - void SetGlobal( const CString &sName, int val ); void SetGlobal( const CString &sName, bool val ); void SetGlobal( const CString &sName, const CString &val ); @@ -102,6 +99,9 @@ namespace LuaHelpers 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 ); + template void ReadArrayFromTable( vector &aOut, lua_State *L ) { diff --git a/stepmania/src/ThemeManager.cpp b/stepmania/src/ThemeManager.cpp index a27724c663..c874e9f46e 100644 --- a/stepmania/src/ThemeManager.cpp +++ b/stepmania/src/ThemeManager.cpp @@ -698,7 +698,7 @@ void ThemeManager::EvaluateString( CString &sText ) { /* If the string begins with an @, treat it as a Lua expression. * Still do font aliases on the resulting string. */ - LUA->RunAtExpressionS( sText ); + LuaHelpers::RunAtExpressionS( sText ); // "::" 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"