diff --git a/stepmania/src/ActorCommands.cpp b/stepmania/src/ActorCommands.cpp index 7a697e2233..2670efe72d 100644 --- a/stepmania/src/ActorCommands.cpp +++ b/stepmania/src/ActorCommands.cpp @@ -91,7 +91,7 @@ void ActorCommands::Register() Lua *L = LUA->Get(); CString sError; - if( !LUA->RunScript( m_sLuaFunction, "in", sError, 1 ) ) + if( !LuaHelpers::RunScript( L, m_sLuaFunction, "in", sError, 1 ) ) { FAIL_M( ssprintf("Compiling \"%s\": %s", m_sLuaFunction.c_str(), sError.c_str()) ); } diff --git a/stepmania/src/LuaManager.cpp b/stepmania/src/LuaManager.cpp index 50c0fe06dd..d0331faefc 100644 --- a/stepmania/src/LuaManager.cpp +++ b/stepmania/src/LuaManager.cpp @@ -248,7 +248,7 @@ bool LuaManager::RunScriptFile( const CString &sFile ) } CString sError; - if( !RunScript( sScript, sFile, sError, 0 ) ) + if( !LuaHelpers::RunScript( L, sScript, sFile, sError, 0 ) ) { sError = ssprintf( "Lua runtime error: %s", sError.c_str() ); Dialog::OK( sError, "LUA_ERROR" ); @@ -258,7 +258,7 @@ bool LuaManager::RunScriptFile( const CString &sFile ) return true; } -bool LuaManager::RunScript( const CString &sScript, const CString &sName, CString &sError, int iReturnValues ) +bool LuaHelpers::RunScript( Lua *L, const CString &sScript, const CString &sName, CString &sError, int iReturnValues ) { // load string { @@ -290,7 +290,7 @@ bool LuaManager::RunScript( const CString &sScript, const CString &sName, CStrin bool LuaManager::RunScript( const CString &sExpression, const CString &sName, int iReturnValues ) { CString sError; - if( !RunScript( sExpression, sName.size()? sName:CString("in"), sError, iReturnValues ) ) + if( !LuaHelpers::RunScript( L, sExpression, sName.size()? sName:CString("in"), sError, iReturnValues ) ) { sError = ssprintf( "Lua runtime error parsing \"%s\": %s", sName.size()? sName.c_str():sExpression.c_str(), sError.c_str() ); Dialog::OK( sError, "LUA_ERROR" ); diff --git a/stepmania/src/LuaManager.h b/stepmania/src/LuaManager.h index 5840ddc443..7458e848a3 100644 --- a/stepmania/src/LuaManager.h +++ b/stepmania/src/LuaManager.h @@ -61,10 +61,6 @@ public: /* Reset the environment, freeing any globals left over by previously executed scripts. */ void ResetState(); - /* Run a script with the given name. Return values are left on the Lua stack. - * Returns false on error, with sError set*/ - bool RunScript( const CString &sScript, const CString &sName, CString &sError, int iReturnValues = 0 ); - /* Convenience: run a script with one return value, displaying an error on failure. * The return value is left on the Lua stack. */ bool RunScript( const CString &sExpression, const CString &sName = "", int iReturnValues = 0 ); @@ -97,6 +93,10 @@ private: namespace LuaHelpers { + /* Run a script with the given name. Return values are left on the Lua stack. + * Returns false on error, with sError set. */ + bool RunScript( Lua *L, const CString &sScript, const CString &sName, CString &sError, int iReturnValues = 0 ); + /* Create a Lua array (a table with indices starting at 1) of the given vector, * and push it on the stack. */ void CreateTableFromArrayB( Lua *L, const vector &aIn ); diff --git a/stepmania/src/LuaReference.cpp b/stepmania/src/LuaReference.cpp index 63c7632034..a2c66ca13e 100644 --- a/stepmania/src/LuaReference.cpp +++ b/stepmania/src/LuaReference.cpp @@ -190,7 +190,7 @@ void LuaData::LoadFromString( const CString &s ) /* Restore the serialized data by evaluating it. */ CString sError; - if( !LUA->RunScript( s, "serialization", sError, 1 ) ) + if( !LuaHelpers::RunScript( L, s, "serialization", sError, 1 ) ) { /* Serialize() should never return an invalid script. Drop the failed * script into the log (it may be too big to pass to FAIL_M) and fail. */