Better error handling in 'Call a Lua Function' k2node

This commit is contained in:
2025-04-07 18:00:45 -04:00
parent d35125eb70
commit 865297331a
6 changed files with 90 additions and 29 deletions

View File

@@ -491,6 +491,14 @@ void World::probe_lua_call(int64_t actor_id, int64_t place_id, std::string_view
lthread_prints_.reset();
util::dprint(prints);
// If a probe generates a lua error, we're not supposed to dprint it.
// Instead, we're supposed to send it back to unreal as the first
// return value of the function.
//
int64_t rv_base = retvals->total_writes();
retvals->write_simple_dynamic_tag(SimpleDynamicTag::STRING);
retvals->write_string(msg);
if (msg.empty()) {
bool ok = true;
for (int i = 0; ok && (i < returnvalues.size()); i++) {
@@ -514,8 +522,12 @@ void World::probe_lua_call(int64_t actor_id, int64_t place_id, std::string_view
ok = encode_simple_dynamic(LS, retvec, retvals);
}
}
} else {
util::dprint(msg);
if (!ok) {
msg = util::ss("Lua function ",classname,".",funcname," returned a non-serializable value");
retvals->unwrite_to(rv_base);
retvals->write_simple_dynamic_tag(SimpleDynamicTag::STRING);
retvals->write_string(msg);
}
}
close_lthread_state();