At this point, most functions have been LuaStack refactored

This commit is contained in:
2023-04-07 14:20:45 -04:00
parent 44c5a56172
commit 4f0713c9cb
9 changed files with 240 additions and 161 deletions

View File

@@ -12,14 +12,14 @@ class DeserializeError {
class Deserializer {
LuaVar id_to_value_;
LuaOldStack LS_;
LuaExtStack LS_;
eng::string &error_;
StreamBuffer *sb_;
int next_id_;
void deserialize_table_r(LuaSlot target) {
LuaVar key, val;
LuaOldStack LS(LS_.state(), key, val);
LuaExtStack LS(LS_.state(), key, val);
LS.newtable(target);
LS.rawset(id_to_value_, next_id_++, target);
bool hasmeta = sb_->read_bool();
@@ -124,7 +124,6 @@ public:
lua_settop(LS_.state(), top);
LS_.set(val, LuaNil);
}
LS_.result();
}
};
@@ -137,14 +136,14 @@ public:
class Serializer {
LuaVar lookup_;
LuaVar value_to_id_;
LuaOldStack LS_;
LuaExtStack LS_;
eng::string &error_;
StreamBuffer *sb_;
int next_id_;
void serialize_table_r(LuaSlot tab) {
LuaVar key, val;
LuaOldStack SLS(LS_.state(), key, val);
LuaExtStack SLS(LS_.state(), key, val);
sb_->write_uint8(LUA_TT_GENERAL);
SLS.getmetatable(val, tab);
if (SLS.isnil(val)) {
@@ -157,17 +156,14 @@ class Serializer {
while (SLS.next(tab, key, val)) {
serialize_r(key);
if (!error_.empty()) {
SLS.result();
return;
}
serialize_r(val);
if (!error_.empty()) {
SLS.result();
return;
}
}
sb_->write_uint8(LUA_PK_ENDTABLE);
SLS.result();
}
void serialize_r(LuaSlot val) {
@@ -270,7 +266,6 @@ public:
LS_.newtable(value_to_id_);
sb_->write_uint16(0xD096);
serialize_r(val);
LS_.result();
}
};
@@ -328,7 +323,7 @@ LuaDefine(table_serialize, "value",
"|") {
LuaArg value;
LuaRet str;
LuaOldStack LS(L, value, str);
LuaDefStack LS(L, value, str);
StreamBuffer sb;
eng::string error = serialize_lua(LS, value, &sb);
if (!error.empty()) {
@@ -347,7 +342,7 @@ LuaDefine(table_deserialize, "binary",
"|") {
LuaArg str;
LuaRet value;
LuaOldStack LS(L, value, str);
LuaDefStack LS(L, value, str);
std::string_view s = LS.ckstringview(str);
StreamBuffer sb(s);
eng::string error = deserialize_lua(LS, value, &sb);