Move some stuff out of LuaStack

This commit is contained in:
2026-02-24 23:44:10 -05:00
parent 2c2d4e44bb
commit 829537a8d6
11 changed files with 407 additions and 410 deletions

View File

@@ -8,6 +8,21 @@
#include <cassert>
class LuaByteReader {
private:
const char *data_;
int64_t size_;
public:
LuaByteReader(const char *d, int64_t s) : data_(d), size_(s) {}
static const char *lua_reader(lua_State *L, void *ud, size_t *size) {
LuaByteReader *reader = (LuaByteReader*)ud;
*size = reader->size_;
const char *data = reader->data_;
reader->data_ = 0;
reader->size_ = 0;
return data;
}
};
LuaSnap::LuaSnap() {
state_ = LuaCoreStack::newstate(eng::l_alloc);
@@ -86,7 +101,7 @@ void LuaSnap::deserialize(StreamBuffer *sb) {
// Lua stack should be empty.
assert(lua_gettop(state_) == 0);
// Get the eris data and convert it to a LuaByteReader.
// Get the eris data and convert it to a byte reader.
int64_t eris_len = sb->read_int64();
const char *eris_bytes = sb->read_bytes(eris_len);
LuaByteReader bytereader(eris_bytes, eris_len);
@@ -94,7 +109,7 @@ void LuaSnap::deserialize(StreamBuffer *sb) {
// Call eris with the permanents table and passing the snapshot as a lua_Reader.
lua_pushstring(state_, "unpersist");
lua_rawget(state_, LUA_REGISTRYINDEX);
eris_undump(state_, bytereader.lua_reader, bytereader.lua_reader_userdata());
eris_undump(state_, bytereader.lua_reader, &bytereader);
// Set up a stack frame manually. Eris deserialization
// should have left permstable and regcopy on the stack.