Better code reload

This commit is contained in:
2026-05-27 14:50:34 -04:00
parent d737879ed6
commit 779c9f5c2e
9 changed files with 31 additions and 64 deletions

View File

@@ -536,25 +536,30 @@ void World::probe_lua_call(int64_t actor_id, int64_t place_id, std::string_view
// in top-level code.
//
bool World::rebuild_sourcedb(int64_t actor_id) {
bool ok = true;
int successes = 0;
int failures = 0;
for (const eng::string &mod: source_db_.modules()) {
open_lthread_state(0, 0, 0, false);
eng::string err = source_db_.rebuild_module(mod);
eng::string prints = lthread_prints_.str();
clear_lthread_state();
if (!err.empty()) ok = false;
if (actor_id >= 0) {
lthread_prints_ << "Compiling " << mod << std::endl;
if (err.empty()) successes ++;
else failures ++;
if ((!err.empty()) || (!prints.empty())) {
lthread_prints_ << "Compiling " << mod << ":" << std::endl;
if (!err.empty()) lthread_prints_ << err << std::endl;
if (!prints.empty()) lthread_prints_ << prints;
lthread_prints_to_actor(actor_id);
util::dprintview(lthread_prints_.view());
if (actor_id != 0) lthread_prints_to_actor(actor_id);
}
}
if (actor_id > 0) {
lthread_prints_ << (ok ? "Compilation Successful." : "Compilation Failed.") << std::endl;
lthread_prints_to_actor(actor_id);
lthread_prints_ << "Compiled " << successes << " modules successfully." << std::endl;
if (failures > 0) {
lthread_prints_ << "Compiled " << failures << " modules with errors." << std::endl;
}
return ok;
util::dprintview(lthread_prints_.view());
if (actor_id > 0) lthread_prints_to_actor(actor_id);
return (failures == 0);
}
bool World::update_source(const util::LuaSourceVec &source, int64_t actor_id) {
@@ -698,7 +703,7 @@ HttpServerResponse World::http_serve(const HttpParser &request) {
open_lthread_state(0, 0, 0, false);
eng::string msg = traceback_pcall(L, 1, LUA_MULTRET);
if (!msg.empty()) lthread_prints_ << msg << std::endl;
lthread_prints_to_actor(0);
util::dprintview(lthread_prints_.view());
clear_lthread_state();
// If the call threw an error, return
@@ -1167,13 +1172,9 @@ void World::lthread_prints_to_actor(int64_t actor_id)
{
const eng::string &output = lthread_prints_.str();
if (output.size() > 0) {
if (actor_id >= 0) {
Tangible *actor = tangible_get(actor_id);
if (actor != nullptr) {
actor->print_buffer_.add_string(output, is_authoritative());
} else {
util::dprintview(output);
}
Tangible *actor = tangible_get(actor_id);
if (actor != nullptr) {
actor->print_buffer_.add_string(output, is_authoritative());
}
lthread_prints_.str("");
lthread_prints_.clear();