lua locking

This commit is contained in:
Glenn Maynard
2005-06-16 22:10:24 +00:00
parent 8a2334b4bf
commit c0a65b3503
4 changed files with 31 additions and 19 deletions
+10 -6
View File
@@ -850,21 +850,25 @@ void Actor::AddRotationR( float rot )
void Actor::RunCommands( const LuaReference& cmds, Actor *pParent ) void Actor::RunCommands( const LuaReference& cmds, Actor *pParent )
{ {
Lua *L = LUA->Get();
// function // function
cmds.PushSelf( LUA->L ); cmds.PushSelf( L );
ASSERT( !lua_isnil(LUA->L, -1) ); ASSERT( !lua_isnil(L, -1) );
// 1st parameter // 1st parameter
this->PushSelf( LUA->L ); this->PushSelf( L );
// 2nd parameter // 2nd parameter
if( pParent ) if( pParent )
pParent->PushSelf( LUA->L ); pParent->PushSelf( L );
else else
lua_pushnil( LUA->L ); lua_pushnil( L );
// call function with 1 argument and 0 results // 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 ) float Actor::GetCommandsLengthSeconds( const LuaReference& cmds )
+9 -7
View File
@@ -204,13 +204,15 @@ void ActorScroller::UpdateInternal( float fDeltaTime )
void ActorScroller::PositionItem( Actor *pActor, float fPositionOffsetFromCenter, int iItemIndex, int iNumItems ) void ActorScroller::PositionItem( Actor *pActor, float fPositionOffsetFromCenter, int iItemIndex, int iNumItems )
{ {
m_exprTransformFunction.PushSelf( LUA->L ); Lua *L = LUA->Get();
ASSERT( !lua_isnil(LUA->L, -1) ); m_exprTransformFunction.PushSelf( L );
pActor->PushSelf( LUA->L ); ASSERT( !lua_isnil(L, -1) );
LuaHelpers::Push( fPositionOffsetFromCenter, LUA->L ); pActor->PushSelf( L );
LuaHelpers::Push( iItemIndex, LUA->L ); LuaHelpers::Push( fPositionOffsetFromCenter, L );
LuaHelpers::Push( iNumItems, LUA->L ); LuaHelpers::Push( iItemIndex, L );
lua_call( LUA->L, 4, 0 ); // 4 args, 0 results LuaHelpers::Push( iNumItems, L );
lua_call( L, 4, 0 ); // 4 args, 0 results
LUA->Release(L);
} }
void ActorScroller::DrawPrimitives() void ActorScroller::DrawPrimitives()
+6 -4
View File
@@ -723,14 +723,16 @@ void GameCommand::ApplySelf( const vector<PlayerNumber> &vpns ) const
GAMESTATE->ApplyModifiers( *pn, m_sModifiers ); GAMESTATE->ApplyModifiers( *pn, m_sModifiers );
if( m_LuaFunction.IsSet() ) if( m_LuaFunction.IsSet() )
{ {
Lua *L = LUA->Get();
FOREACH_CONST( PlayerNumber, vpns, pn ) FOREACH_CONST( PlayerNumber, vpns, pn )
{ {
m_LuaFunction.PushSelf( LUA->L ); m_LuaFunction.PushSelf( L );
ASSERT( !lua_isnil(LUA->L, -1) ); ASSERT( !lua_isnil(L, -1) );
lua_pushnumber( LUA->L, *pn ); // 1st parameter lua_pushnumber( L, *pn ); // 1st parameter
lua_call( LUA->L, 1, 0 ); // call function with 1 argument and 0 results lua_call( L, 1, 0 ); // call function with 1 argument and 0 results
} }
LUA->Release(L);
} }
if( m_sScreen != "" ) if( m_sScreen != "" )
SCREENMAN->SetNewScreen( m_sScreen ); SCREENMAN->SetNewScreen( m_sScreen );
+5 -1
View File
@@ -247,13 +247,17 @@ bool LuaHelpers::RunScriptFile( const CString &sFile )
return false; return false;
} }
Lua *L = LUA->Get();
CString sError; 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() ); sError = ssprintf( "Lua runtime error: %s", sError.c_str() );
Dialog::OK( sError, "LUA_ERROR" ); Dialog::OK( sError, "LUA_ERROR" );
return false; return false;
} }
LUA->Release(L);
return true; return true;
} }