Can now use /CPL to reload lua source

This commit is contained in:
2021-12-15 14:18:19 -05:00
parent c689422206
commit e0001127c7
11 changed files with 115 additions and 13 deletions

View File

@@ -375,16 +375,20 @@ void World::update_gui(int64_t actor_id, int64_t place_id, Gui *gui) {
}
void World::update_source(const util::LuaSourcePtr &source) {
assert(stack_is_clear());
if (source != nullptr) {
source_db_.update(*source);
assert(stack_is_clear());
std::string errs = source_db_.rebuild();
// I don't have a good place to send the error messages right
// now. The engine needs a catch-all place to send errors that
// occur at unexpected times.
std::cerr << errs;
update_source(*source);
}
}
void World::update_source(const util::LuaSourceVec &source) {
assert(stack_is_clear());
source_db_.update(source);
assert(stack_is_clear());
std::string errs = source_db_.rebuild();
// I don't have a good place to send the error messages right
// now. The engine needs a catch-all place to send errors that
// occur at unexpected times.
std::cerr << errs;
assert(stack_is_clear());
}
@@ -407,6 +411,10 @@ void World::invoke(const Invocation &inv) {
break;
case Invocation::KIND_TICK:
invoke_tick(inv.actor(), inv.place(), inv.action(), inv.data());
break;
case Invocation::KIND_LUA_SOURCE:
invoke_lua_source(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
@@ -604,9 +612,25 @@ void World::invoke_plan(int64_t actor_id, int64_t place_id, const std::string &a
}
void World::invoke_tick(int64_t actor_id, int64_t place_id, const std::string &action, const InvocationData &data) {
if (util::world_type_authoritative(world_type_)) {
clock_ += 1;
run_scheduled_threads();
if (!util::world_type_authoritative(world_type_)) {
return;
}
clock_ += 1;
run_scheduled_threads();
}
void World::invoke_lua_source(int64_t actor_id, int64_t place_id, const std::string &action, const InvocationData &data) {
if (!util::world_type_authoritative(world_type_)) {
return;
}
// We need some kind of authentication here.
try {
StreamBuffer sb(action);
util::LuaSourceVec sv;
SourceDB::deserialize_source(&sv, &sb);
update_source(sv);
} catch (const StreamException &ex) {
return;
}
}