Messages and commands are nearly identical: they both have a name,
they can both have parameters stashed in a table, and they both play stuff out of the actor command list. Merge them; now the only difference between playing and broadcasting a command is that playing plays recursively on a tree and broadcasting sends to all subscribers. The distinction between "messages" and "commands" is cosmetic now; everything is a message. The only thing special about commands intended to be received as a broadcast is the "Message" suffix, which subscribes it.
This commit is contained in:
@@ -158,6 +158,17 @@ Message::Message( const RString &s )
|
||||
m_pParams = new LuaTable;
|
||||
}
|
||||
|
||||
Message::Message( const RString &s, const LuaReference ¶ms )
|
||||
{
|
||||
m_sName = s;
|
||||
Lua *L = LUA->Get();
|
||||
m_pParams = new LuaTable; // XXX: creates an extra table
|
||||
params.PushSelf( L );
|
||||
m_pParams->SetFromStack( L );
|
||||
LUA->Release( L );
|
||||
// m_pParams = new LuaTable( params );
|
||||
}
|
||||
|
||||
Message::~Message()
|
||||
{
|
||||
delete m_pParams;
|
||||
@@ -168,6 +179,14 @@ void Message::PushParamTable( lua_State *L )
|
||||
m_pParams->PushSelf( L );
|
||||
}
|
||||
|
||||
void Message::SetParamTable( const LuaReference ¶ms )
|
||||
{
|
||||
Lua *L = LUA->Get();
|
||||
params.PushSelf( L );
|
||||
m_pParams->SetFromStack( L );
|
||||
LUA->Release( L );
|
||||
}
|
||||
|
||||
const LuaReference &Message::GetParamTable() const
|
||||
{
|
||||
return *m_pParams;
|
||||
@@ -305,7 +324,8 @@ public:
|
||||
lua_pushvalue( L, 2 );
|
||||
ParamTable.SetFromStack( L );
|
||||
|
||||
p->Broadcast( SArg(1) );
|
||||
Message msg( SArg(1), ParamTable );
|
||||
p->Broadcast( msg );
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user