Plan invocations are now serializable objects
This commit is contained in:
@@ -265,7 +265,22 @@ void World::update_gui(int64_t actor_id, int64_t place_id, Gui *gui) {
|
||||
assert(stack_is_clear());
|
||||
}
|
||||
|
||||
void World::invoke_plan(int64_t actor_id, int64_t place_id, const std::string &action, const GuiResult &gres) {
|
||||
void World::invoke(const Invocation &inv) {
|
||||
switch (inv.kind()) {
|
||||
case Invocation::KIND_PLAN:
|
||||
invoke_plan(inv.actor(), inv.place(), inv.action(), inv.data());
|
||||
break;
|
||||
default:
|
||||
// Do nothing. Standard behavior for any invalid command is to
|
||||
// simply do nothing at all. Perhaps eventually we may add a flag
|
||||
// to the world model to indicate that we've detected an invalid
|
||||
// command, to allow us to close the connection to a client that
|
||||
// is misbehaving.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void World::invoke_plan(int64_t actor_id, int64_t place_id, const std::string &action, const InvocationData &idata) {
|
||||
assert(stack_is_clear());
|
||||
|
||||
// Validate that the action is legal.
|
||||
@@ -288,8 +303,8 @@ void World::invoke_plan(int64_t actor_id, int64_t place_id, const std::string &a
|
||||
|
||||
// Set up for Lua manipulation.
|
||||
lua_State *L = state();
|
||||
LuaVar actor, place, func, tangibles, mt, index, actions, thread, threads, message, guires;
|
||||
LuaStack LS(L, actor, place, func, tangibles, mt, index, actions, thread, threads, message, guires);
|
||||
LuaVar actor, place, func, tangibles, mt, index, actions, thread, threads, message, invdata;
|
||||
LuaStack LS(L, actor, place, func, tangibles, mt, index, actions, thread, threads, message, invdata);
|
||||
|
||||
// Get the actor and place.
|
||||
LS.rawget(tangibles, LuaRegistry, "tangibles");
|
||||
@@ -322,10 +337,10 @@ void World::invoke_plan(int64_t actor_id, int64_t place_id, const std::string &a
|
||||
return;
|
||||
}
|
||||
|
||||
// Convert the GuiResult into a lua table.
|
||||
LS.newtable(guires);
|
||||
for (const auto &p : gres) {
|
||||
LS.rawset(guires, p.first, p.second);
|
||||
// Convert the InvocationData into a lua table.
|
||||
LS.newtable(invdata);
|
||||
for (const auto &p : idata) {
|
||||
LS.rawset(invdata, p.first, p.second);
|
||||
}
|
||||
|
||||
// Create a new thread, set up function and parameters.
|
||||
@@ -333,7 +348,7 @@ void World::invoke_plan(int64_t actor_id, int64_t place_id, const std::string &a
|
||||
lua_pushvalue(L, func.index());
|
||||
lua_pushvalue(L, actor.index());
|
||||
lua_pushvalue(L, place.index());
|
||||
lua_pushvalue(L, guires.index());
|
||||
lua_pushvalue(L, invdata.index());
|
||||
lua_xmove(L, CO, 4);
|
||||
|
||||
// Store the thread into place's thread table.
|
||||
|
||||
Reference in New Issue
Block a user