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 //