Changes related to ray-collision, and luprex global variable stuff

This commit is contained in:
2025-01-14 18:37:31 -05:00
parent cd3e78a206
commit a01f6f4e7b
24 changed files with 180 additions and 317 deletions

View File

@@ -241,32 +241,6 @@ void World::tangible_set_class(int64_t id, const eng::string &c) const {
LS.rawset(meta, "__index", sclass);
}
void World::set_global_json(const eng::string &gvar, const eng::string &json) {
LuaVar decoded;
LuaExtStack LS(state(), decoded);
bool ok = json::decode(LS, decoded, json);
if (!ok) {
luaL_error(state(), "invalid json");
return;
}
set_global(LS, gvar, decoded);
}
eng::string World::get_global_json(const eng::string &gvar) {
LuaVar value, globaldb;
LuaExtStack LS(state(), globaldb, value);
LS.rawget(globaldb, LuaRegistry, "globaldb");
LS.rawget(value, globaldb, gvar);
eng::string out;
eng::string error = json::encode(LS, value, out, false, 10000);
if (!error.empty()) {
luaL_error(state(), "%s", error.c_str());
return "";
}
return out;
}
eng::string World::tangible_get_class(int64_t id) const {
LuaVar tangibles, tan, meta, sclass;
LuaExtStack LS(state(), tangibles, tan, meta, sclass);
@@ -495,24 +469,24 @@ LuaDefine(unittests_world5diffglobals, "", "some unit tests") {
UniqueWorld cs(new World(WORLD_TYPE_PREDICTIVE));
StreamBuffer sb;
m->set_global_json("x", "3");
m->set_global("x", "3");
ss->diff_globals(m.get(), &sb);
cs->patch_globals(&sb, nullptr);
LuaAssertStrEq(L, cs->get_global_json("x"), "3");
LuaAssertStrEq(L, cs->get_global("x"), "3");
m->set_global_json("x", "4");
m->set_global_json("x", "5");
m->set_global_json("y", "6");
m->set_global("x", "4");
m->set_global("x", "5");
m->set_global("y", "6");
ss->diff_globals(m.get(), &sb);
cs->patch_globals(&sb, nullptr);
LuaAssertStrEq(L, cs->get_global_json("x"), "5");
LuaAssertStrEq(L, cs->get_global_json("y"), "6");
LuaAssertStrEq(L, cs->get_global("x"), "5");
LuaAssertStrEq(L, cs->get_global("y"), "6");
cs->set_global_json("x", "2");
ss->set_global_json("x", "2");
cs->set_global("x", "2");
ss->set_global("x", "2");
ss->diff_globals(m.get(), &sb);
cs->patch_globals(&sb, nullptr);
LuaAssertStrEq(L, cs->get_global_json("x"), "5");
LuaAssertStrEq(L, cs->get_global("x"), "5");
return 0;
}