diff --git a/stepmania/src/Actor.cpp b/stepmania/src/Actor.cpp index 47172ea93e..1982bebd0f 100644 --- a/stepmania/src/Actor.cpp +++ b/stepmania/src/Actor.cpp @@ -850,21 +850,25 @@ void Actor::AddRotationR( float rot ) void Actor::RunCommands( const LuaReference& cmds, Actor *pParent ) { + Lua *L = LUA->Get(); + // function - cmds.PushSelf( LUA->L ); - ASSERT( !lua_isnil(LUA->L, -1) ); + cmds.PushSelf( L ); + ASSERT( !lua_isnil(L, -1) ); // 1st parameter - this->PushSelf( LUA->L ); + this->PushSelf( L ); // 2nd parameter if( pParent ) - pParent->PushSelf( LUA->L ); + pParent->PushSelf( L ); else - lua_pushnil( LUA->L ); + lua_pushnil( L ); // call function with 1 argument and 0 results - lua_call(LUA->L, 2, 0); + lua_call( L, 2, 0 ); + + LUA->Release(L); } float Actor::GetCommandsLengthSeconds( const LuaReference& cmds ) diff --git a/stepmania/src/ActorScroller.cpp b/stepmania/src/ActorScroller.cpp index 5ac3fd23c4..b5961ef10a 100644 --- a/stepmania/src/ActorScroller.cpp +++ b/stepmania/src/ActorScroller.cpp @@ -204,13 +204,15 @@ void ActorScroller::UpdateInternal( float fDeltaTime ) void ActorScroller::PositionItem( Actor *pActor, float fPositionOffsetFromCenter, int iItemIndex, int iNumItems ) { - m_exprTransformFunction.PushSelf( LUA->L ); - ASSERT( !lua_isnil(LUA->L, -1) ); - pActor->PushSelf( LUA->L ); - LuaHelpers::Push( fPositionOffsetFromCenter, LUA->L ); - LuaHelpers::Push( iItemIndex, LUA->L ); - LuaHelpers::Push( iNumItems, LUA->L ); - lua_call( LUA->L, 4, 0 ); // 4 args, 0 results + Lua *L = LUA->Get(); + m_exprTransformFunction.PushSelf( L ); + ASSERT( !lua_isnil(L, -1) ); + pActor->PushSelf( L ); + LuaHelpers::Push( fPositionOffsetFromCenter, L ); + LuaHelpers::Push( iItemIndex, L ); + LuaHelpers::Push( iNumItems, L ); + lua_call( L, 4, 0 ); // 4 args, 0 results + LUA->Release(L); } void ActorScroller::DrawPrimitives() diff --git a/stepmania/src/GameCommand.cpp b/stepmania/src/GameCommand.cpp index a6c34c3062..ee8cb3e9b9 100644 --- a/stepmania/src/GameCommand.cpp +++ b/stepmania/src/GameCommand.cpp @@ -723,14 +723,16 @@ void GameCommand::ApplySelf( const vector &vpns ) const GAMESTATE->ApplyModifiers( *pn, m_sModifiers ); if( m_LuaFunction.IsSet() ) { + Lua *L = LUA->Get(); FOREACH_CONST( PlayerNumber, vpns, pn ) { - m_LuaFunction.PushSelf( LUA->L ); - ASSERT( !lua_isnil(LUA->L, -1) ); + m_LuaFunction.PushSelf( L ); + ASSERT( !lua_isnil(L, -1) ); - lua_pushnumber( LUA->L, *pn ); // 1st parameter - lua_call( LUA->L, 1, 0 ); // call function with 1 argument and 0 results + lua_pushnumber( L, *pn ); // 1st parameter + lua_call( L, 1, 0 ); // call function with 1 argument and 0 results } + LUA->Release(L); } if( m_sScreen != "" ) SCREENMAN->SetNewScreen( m_sScreen ); diff --git a/stepmania/src/LuaManager.cpp b/stepmania/src/LuaManager.cpp index 85ff9ff196..05af0a1345 100644 --- a/stepmania/src/LuaManager.cpp +++ b/stepmania/src/LuaManager.cpp @@ -247,14 +247,18 @@ bool LuaHelpers::RunScriptFile( const CString &sFile ) return false; } + Lua *L = LUA->Get(); + CString sError; - if( !LuaHelpers::RunScript( LUA->L, sScript, sFile, sError, 0 ) ) + if( !LuaHelpers::RunScript( L, sScript, sFile, sError, 0 ) ) { + LUA->Release(L); sError = ssprintf( "Lua runtime error: %s", sError.c_str() ); Dialog::OK( sError, "LUA_ERROR" ); return false; } - + LUA->Release(L); + return true; }