Added invoke_plan, removed viewer
This commit is contained in:
@@ -140,8 +140,8 @@ void World::update_gui(int64_t actor_id, int64_t place_id, Gui *gui) {
|
||||
gui->clear();
|
||||
lua_State *L = state();
|
||||
|
||||
LuaVar actor, place, ugui, func, tangibles;
|
||||
LuaStack LS(L, actor, place, ugui, func, tangibles);
|
||||
LuaVar actor, place, ugui, func, tangibles, mt, index;
|
||||
LuaStack LS(L, actor, place, ugui, func, tangibles, mt, index);
|
||||
|
||||
// Get the actor and place.
|
||||
LS.rawget(tangibles, LuaRegistry, "tangibles");
|
||||
@@ -153,8 +153,17 @@ void World::update_gui(int64_t actor_id, int64_t place_id, Gui *gui) {
|
||||
}
|
||||
|
||||
// Get the interface closure.
|
||||
// Use of 'gettable' instead of 'rawget' is deliberate.
|
||||
LS.gettable(func, place, "interface");
|
||||
LS.getmetatable(mt, place);
|
||||
if (!LS.istable(mt)) {
|
||||
LS.result();
|
||||
return;
|
||||
}
|
||||
LS.rawget(index, mt, "__index");
|
||||
if (!LS.istable(index)) {
|
||||
LS.result();
|
||||
return;
|
||||
}
|
||||
LS.rawget(func, index, "interface");
|
||||
if (!LS.isfunction(func)) {
|
||||
LS.result();
|
||||
return;
|
||||
@@ -182,7 +191,67 @@ void World::update_gui(int64_t actor_id, int64_t place_id, Gui *gui) {
|
||||
// And we're done.
|
||||
LS.result();
|
||||
}
|
||||
|
||||
void World::invoke_plan(int64_t actor_id, int64_t place_id, const std::string &action, Gui *gui) {
|
||||
lua_State *L = state();
|
||||
|
||||
LuaVar actor, place, ugui, func, tangibles, mt, index, actions;
|
||||
LuaStack LS(L, actor, place, ugui, func, tangibles, mt, index, actions);
|
||||
|
||||
// Get the actor and place.
|
||||
LS.rawget(tangibles, LuaRegistry, "tangibles");
|
||||
LS.rawget(actor, tangibles, actor_id);
|
||||
LS.rawget(place, tangibles, place_id);
|
||||
if (!LS.istable(actor) || !LS.istable(place)) {
|
||||
LS.result();
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the action closure.
|
||||
LS.getmetatable(mt, place);
|
||||
if (!LS.istable(mt)) {
|
||||
LS.result();
|
||||
return;
|
||||
}
|
||||
LS.rawget(index, mt, "__index");
|
||||
if (!LS.istable(index)) {
|
||||
LS.result();
|
||||
return;
|
||||
}
|
||||
LS.rawget(actions, index, "action");
|
||||
if (!LS.istable(actions)) {
|
||||
LS.result();
|
||||
return;
|
||||
}
|
||||
LS.rawget(func, actions, action);
|
||||
if (!LS.isfunction(func)) {
|
||||
LS.result();
|
||||
return;
|
||||
}
|
||||
|
||||
// Construct the userdata with the GUI pointer.
|
||||
LS.newpointer<Gui>(ugui, gui, false);
|
||||
|
||||
// Call the action function.
|
||||
lua_pushvalue(L, func.index());
|
||||
lua_pushvalue(L, actor.index());
|
||||
lua_pushvalue(L, place.index());
|
||||
lua_pushvalue(L, ugui.index());
|
||||
int status = traceback_pcall(L, 3, 0);
|
||||
if (status != 0) {
|
||||
gui->clear();
|
||||
std::cerr << lua_tostring(L, -1);
|
||||
LS.result();
|
||||
return;
|
||||
}
|
||||
|
||||
// Nuke the userdata, in case somebody saved a pointer to it.
|
||||
LS.clearuserdata(ugui);
|
||||
|
||||
// And we're done.
|
||||
LS.result();
|
||||
}
|
||||
|
||||
LuaDefine(tangible_get, "c") {
|
||||
LuaArg id;
|
||||
LuaRet database;
|
||||
|
||||
Reference in New Issue
Block a user