Code cleanup and refactoring.

This commit is contained in:
2026-02-09 13:54:00 -05:00
parent 56765fdc16
commit db35967fb9
23 changed files with 271 additions and 275 deletions

View File

@@ -8,17 +8,17 @@
#include <iostream>
// Read a SimpleDynamic value from the streambuffer and push
// Read a LuaValueHolder value from the streambuffer and push
// it onto the lua stack.
void push_simple_dynamic(lua_State *L, StreamBuffer *sb) {
SimpleDynamicTag type = sb->read_simple_dynamic_tag();
LuaValueType type = sb->read_simple_dynamic_tag();
switch (type) {
case SimpleDynamicTag::STRING: {
case LuaValueType::STRING: {
std::string_view s = sb->read_string_view();
lua_pushlstring(L, s.data(), s.size());
break;
}
case SimpleDynamicTag::TOKEN: {
case LuaValueType::TOKEN: {
std::string_view toktext = sb->read_string_view();
LuaToken token(toktext);
if (token.empty() && !toktext.empty()) {
@@ -27,15 +27,15 @@ void push_simple_dynamic(lua_State *L, StreamBuffer *sb) {
lua_pushlightuserdata(L, token.voidvalue());
break;
}
case SimpleDynamicTag::NUMBER: {
case LuaValueType::NUMBER: {
lua_pushnumber(L, sb->read_double());
break;
}
case SimpleDynamicTag::BOOLEAN: {
case LuaValueType::BOOLEAN: {
lua_pushboolean(L, sb->read_bool() ? 1:0);
break;
}
case SimpleDynamicTag::VECTOR: {
case LuaValueType::VECTOR: {
double x = sb->read_double();
double y = sb->read_double();
double z = sb->read_double();
@@ -56,25 +56,25 @@ void push_simple_dynamic(lua_State *L, StreamBuffer *sb) {
bool encode_simple_dynamic(LuaCoreStack &LS, LuaSlot &slot, StreamBuffer *sb) {
switch (LS.type(slot)) {
case LUA_TSTRING:
sb->write_simple_dynamic_tag(SimpleDynamicTag::STRING);
sb->write_simple_dynamic_tag(LuaValueType::STRING);
sb->write_string(LS.ckstringview(slot));
return true;
case LUA_TLIGHTUSERDATA:
sb->write_simple_dynamic_tag(SimpleDynamicTag::TOKEN);
sb->write_simple_dynamic_tag(LuaValueType::TOKEN);
sb->write_string(LS.cktoken(slot).str());
return true;
case LUA_TNUMBER:
sb->write_simple_dynamic_tag(SimpleDynamicTag::NUMBER);
sb->write_simple_dynamic_tag(LuaValueType::NUMBER);
sb->write_double(LS.cknumber(slot));
return true;
case LUA_TBOOLEAN:
sb->write_simple_dynamic_tag(SimpleDynamicTag::BOOLEAN);
sb->write_simple_dynamic_tag(LuaValueType::BOOLEAN);
sb->write_bool(LS.ckboolean(slot));
return true;
case LUA_TTABLE: {
std::optional<util::DXYZ> xyz = LS.tryxyz(slot);
if (!xyz.has_value()) return false;
sb->write_simple_dynamic_tag(SimpleDynamicTag::VECTOR);
sb->write_simple_dynamic_tag(LuaValueType::VECTOR);
sb->write_dxyz(xyz.value());
return true;
}
@@ -492,7 +492,7 @@ void World::probe_lua_call(int64_t actor_id, int64_t place_id, std::string_view
// return value of the function.
//
int64_t rv_base = retvals->total_writes();
retvals->write_simple_dynamic_tag(SimpleDynamicTag::STRING);
retvals->write_simple_dynamic_tag(LuaValueType::STRING);
retvals->write_string(msg);
if (msg.empty()) {
@@ -521,7 +521,7 @@ void World::probe_lua_call(int64_t actor_id, int64_t place_id, std::string_view
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_simple_dynamic_tag(LuaValueType::STRING);
retvals->write_string(msg);
}
}