fix RunCommandsRecursively by implementing it directly

distinguish between Run ("call this function") and Play
("look up the function with this name and call it")
This commit is contained in:
Glenn Maynard
2007-02-20 23:49:13 +00:00
parent f0c7d92fb5
commit 2fa8986ea6
4 changed files with 33 additions and 1 deletions
+18
View File
@@ -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 );
+6 -1
View File
@@ -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); }
+7
View File
@@ -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; i<m_SubActors.size(); i++ )
m_SubActors[i]->RunCommandsRecursively( cmds, pParamTable );
Actor::RunCommandsRecursively( cmds, pParamTable );
}
void ActorFrame::RunCommandsOnChildren( const LuaReference& cmds, const LuaReference *pParamTable )
{
for( unsigned i=0; i<m_SubActors.size(); i++ )
+2
View File
@@ -40,6 +40,8 @@ public:
void PushChildrenTable( lua_State *L );
void PlayCommandOnChildren( const RString &sCommandName, const LuaReference *pParamTable = NULL );
void PlayCommandOnLeaves( const RString &sCommandName, const LuaReference *pParamTable = NULL );
virtual void RunCommandsRecursively( const LuaReference& cmds, const LuaReference *pParamTable = NULL );
virtual void RunCommandsOnChildren( const LuaReference& cmds, const LuaReference *pParamTable = NULL ); /* but not on self */
void RunCommandsOnChildren( const apActorCommands& cmds, const LuaReference *pParamTable = NULL ) { this->RunCommandsOnChildren( *cmds, pParamTable ); } // convenience
virtual void RunCommandsOnLeaves( const LuaReference& cmds, const LuaReference *pParamTable = NULL ); /* but not on self */