diff --git a/stepmania/src/Actor.cpp b/stepmania/src/Actor.cpp index 768f8fb281..d1ac020b36 100644 --- a/stepmania/src/Actor.cpp +++ b/stepmania/src/Actor.cpp @@ -1347,6 +1347,23 @@ public: return 1; } + static int RunCommandsRecursively( T* p, lua_State *L ) + { + luaL_checktype( L, 1, LUA_TFUNCTION ); + if( !lua_istable(L, 2) && !lua_isnoneornil(L, 2) ) + luaL_typerror( L, 2, "table or nil" ); + + LuaReference ref; + lua_pushvalue( L, 1 ); + ref.SetFromStack( L ); + + LuaReference ParamTable; + lua_pushvalue( L, 2 ); + ParamTable.SetFromStack( L ); + + p->RunCommandsRecursively( ref, &ParamTable ); + return 0; + } static int GetX( T* p, lua_State *L ) { lua_pushnumber( L, p->GetX() ); return 1; } static int GetY( T* p, lua_State *L ) { lua_pushnumber( L, p->GetY() ); return 1; } @@ -1494,6 +1511,7 @@ public: ADD_METHOD( queuemessage ); ADD_METHOD( addcommand ); ADD_METHOD( GetCommand ); + ADD_METHOD( RunCommandsRecursively ); ADD_METHOD( GetX ); ADD_METHOD( GetY ); diff --git a/stepmania/src/Actor.h b/stepmania/src/Actor.h index c95f1d6780..21a9afeb63 100644 --- a/stepmania/src/Actor.h +++ b/stepmania/src/Actor.h @@ -346,15 +346,20 @@ public: virtual void PushContext( lua_State *L ); // - // Commands + // Named commands // void AddCommand( const RString &sCmdName, apActorCommands apac ); bool HasCommand( const RString &sCmdName ); const apActorCommands *GetCommand( const RString &sCommandName ) const; void PlayCommand( const RString &sCommandName ) { HandleMessage( Message(sCommandName) ); } // convenience void PlayCommandNoRecurse( const Message &sCommandName ); + + // + // Commands by reference + // virtual void RunCommands( const LuaReference& cmds, const LuaReference *pParamTable = NULL ); void RunCommands( const apActorCommands& cmds, const LuaReference *pParamTable = NULL ) { this->RunCommands( *cmds, pParamTable ); } // convenience + virtual void RunCommandsRecursively( const LuaReference& cmds, const LuaReference *pParamTable = NULL ) { RunCommands(cmds, pParamTable); } // If we're a leaf, then execute this command. virtual void RunCommandsOnLeaves( const LuaReference& cmds, const LuaReference *pParamTable = NULL ) { RunCommands(cmds, pParamTable); } diff --git a/stepmania/src/ActorFrame.cpp b/stepmania/src/ActorFrame.cpp index 15c370fd10..b0e78dfc0f 100644 --- a/stepmania/src/ActorFrame.cpp +++ b/stepmania/src/ActorFrame.cpp @@ -277,6 +277,13 @@ void ActorFrame::PlayCommandOnLeaves( const RString &sCommandName, const LuaRefe RunCommandsOnLeaves( **pCmd, pParamTable ); } +void ActorFrame::RunCommandsRecursively( const LuaReference& cmds, const LuaReference *pParamTable ) +{ + for( unsigned i=0; iRunCommandsRecursively( cmds, pParamTable ); + Actor::RunCommandsRecursively( cmds, pParamTable ); +} + void ActorFrame::RunCommandsOnChildren( const LuaReference& cmds, const LuaReference *pParamTable ) { for( unsigned i=0; iRunCommandsOnChildren( *cmds, pParamTable ); } // convenience virtual void RunCommandsOnLeaves( const LuaReference& cmds, const LuaReference *pParamTable = NULL ); /* but not on self */