From 89ab4446931d20d47e28128c21682ee59f8413cc Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Wed, 9 Aug 2006 23:22:54 +0000 Subject: [PATCH] Add parent links to actors. For each actor, create a context table, with an __index link to the parent's. This can be used to propagate information down complex actor trees. Code needs to be changed to do AddChild() calls before loading, rather than after, so context links are available during loads. This will be done as necessary. --- stepmania/src/Actor.cpp | 34 ++++++++++++++++++++++++++++++++++ stepmania/src/Actor.h | 3 +++ 2 files changed, 37 insertions(+) diff --git a/stepmania/src/Actor.cpp b/stepmania/src/Actor.cpp index 60b6dfb13f..14a126e4e8 100644 --- a/stepmania/src/Actor.cpp +++ b/stepmania/src/Actor.cpp @@ -113,6 +113,17 @@ static bool GetMessageNameFromCommandName( const RString &sCommandName, RString Actor::Actor() { m_pLuaInstance = new LuaClass; + Lua *L = LUA->Get(); + m_pLuaInstance->PushSelf( L ); + lua_pushstring( L, "ctx" ); + lua_newtable( L ); + lua_pushvalue( L, -1 ); + lua_setmetatable( L, -2 ); + lua_settable( L, -3 ); + lua_pop( L, 1 ); + LUA->Release( L ); + + m_size = RageVector2( 1, 1 ); InitDefaults(); m_bFirstUpdate = true; @@ -1251,6 +1262,29 @@ void Actor::PlayCommand( const RString &sCommandName, Actor *pParent ) RunCommands( *pCmd ); } +void Actor::PushContext( lua_State *L ) +{ + // self.ctx should already exist + m_pLuaInstance->PushSelf( L ); + lua_pushstring( L, "ctx" ); + lua_gettable( L, -2 ); + lua_replace( L, -2 ); +} + +void Actor::SetParent( Actor *pParent ) +{ + Lua *L = LUA->Get(); + int iTop = lua_gettop( L ); + + this->PushContext( L ); + lua_pushstring( L, "__index" ); + pParent->PushContext( L ); + lua_settable( L, -3 ); + + lua_settop( L, iTop ); + LUA->Release( L ); +} + void Actor::HandleMessage( const RString& sMessage ) { PlayCommand( sMessage ); diff --git a/stepmania/src/Actor.h b/stepmania/src/Actor.h index 9cb9bac35b..8006d5954f 100644 --- a/stepmania/src/Actor.h +++ b/stepmania/src/Actor.h @@ -328,6 +328,7 @@ public: // Lua // virtual void PushSelf( lua_State *L ); + virtual void PushContext( lua_State *L ); // // Commands @@ -341,6 +342,8 @@ public: // If we're a leaf, then execute this command. virtual void RunCommandsOnLeaves( const LuaReference& cmds, Actor *pParent = NULL ) { RunCommands(cmds,pParent); } + void SetParent( Actor *pParent ); + // // Messages //