Restore ability to print return values.
This commit is contained in:
@@ -492,6 +492,7 @@ void World::invoke_lua(int64_t actor_id, int64_t place_id, const std::string &ac
|
||||
LS.rawset(thinfo, "actorid", actor_id);
|
||||
LS.rawset(thinfo, "nargs", 0);
|
||||
LS.rawset(thinfo, "useppool", true);
|
||||
LS.rawset(thinfo, "print", true);
|
||||
|
||||
// Store the thread into place's thread table.
|
||||
LS.rawget(threads, mt, "threads");
|
||||
@@ -584,6 +585,7 @@ void World::invoke_plan(int64_t actor_id, int64_t place_id, const std::string &a
|
||||
LS.rawset(thinfo, "actorid", actor_id);
|
||||
LS.rawset(thinfo, "nargs", 3); // actor, place, invdata
|
||||
LS.rawset(thinfo, "useppool", true);
|
||||
LS.rawset(thinfo, "print", false);
|
||||
|
||||
// Store the thread into place's thread table.
|
||||
LS.rawget(threads, mt, "threads");
|
||||
@@ -611,8 +613,8 @@ void World::invoke_tick(int64_t actor_id, int64_t place_id, const std::string &a
|
||||
void World::run_scheduled_threads() {
|
||||
assert(stack_is_clear());
|
||||
lua_State *L = state();
|
||||
LuaVar tangibles, place, mt, threads, thinfo, actorid, nargs, useppool, thread;
|
||||
LuaStack LS(L, tangibles, place, mt, threads, thinfo, actorid, nargs, useppool, thread);
|
||||
LuaVar tangibles, place, mt, threads, thinfo, actorid, nargs, useppool, thread, print;
|
||||
LuaStack LS(L, tangibles, place, mt, threads, thinfo, actorid, nargs, useppool, thread, print);
|
||||
|
||||
LS.rawget(tangibles, LuaRegistry, "tangibles");
|
||||
while (thread_sched_.ready(clock_)) {
|
||||
@@ -662,7 +664,6 @@ void World::run_scheduled_threads() {
|
||||
} else if (status == LUA_YIELD) {
|
||||
// If there's nothing on the stack, infer that tangible.nopredict yielded.
|
||||
if (lua_gettop(CO) == 0) {
|
||||
// std::cerr << "Thread killed self using tangible.nopredict" << std::endl;
|
||||
LS.rawset(threads, sched.thread_id(), LuaNil);
|
||||
}
|
||||
// If there's a single number on the stack, infer that 'wait' yielded.
|
||||
@@ -671,9 +672,7 @@ void World::run_scheduled_threads() {
|
||||
lua_settop(CO, 0);
|
||||
LS.rawset(thinfo, "nargs", 0);
|
||||
LS.rawset(thinfo, "useppool", false);
|
||||
// std::cerr << "Thread wait = " << delay << std::endl;
|
||||
thread_sched_.add(clock_ + int64_t(delay), sched.thread_id(), sched.place_id());
|
||||
// std::cerr << "Added to schedule." << std::endl;
|
||||
}
|
||||
// In any other case, generate an error and kill the coroutine.
|
||||
else {
|
||||
@@ -681,8 +680,15 @@ void World::run_scheduled_threads() {
|
||||
LS.rawset(threads, sched.thread_id(), LuaNil);
|
||||
}
|
||||
} else if (status == LUA_OK) {
|
||||
// Successfully ran to completion. Remove from thread table.
|
||||
// std::cerr << "Thread ran to completion." << std::endl;
|
||||
// Successfully ran to completion. Print any return values.
|
||||
// Remove from thread table.
|
||||
LS.rawget(print, thinfo, "print");
|
||||
LuaStack LSCO(CO);
|
||||
if (LS.ckboolean(print)) {
|
||||
for (int i = 1; i <= lua_gettop(CO); i++) {
|
||||
pprint(LSCO, LuaSpecial(i), true, ostream);
|
||||
}
|
||||
}
|
||||
LS.rawset(threads, sched.thread_id(), LuaNil);
|
||||
} else {
|
||||
// Generated an error. Add a traceback, print, and kill the coroutine.
|
||||
|
||||
Reference in New Issue
Block a user