More work on table diff xmit

This commit is contained in:
2021-09-07 14:38:46 -04:00
parent 5cefa4f1e2
commit 2165bb578c
3 changed files with 74 additions and 13 deletions

View File

@@ -3,8 +3,15 @@
// This file contains the code to compare the contents of tables.
// The top level functions in this file are:
//
// World::diff_lua_tables
// World::diff_numbered_tables
// World::diff_tangible_databases
// World::patch_numbered_tables
// World::patch_tangible_databases
//
// It also contains these unit testing support routines:
//
// table.diffcompare
// table.diffapply
//
// This file also contains all the support code needed to implement
// this stuff.
@@ -321,6 +328,7 @@ void World::diff_numbered_tables(lua_State *master, StreamBuffer *sb) {
MLS.rawgeti(mtab, mntmap, id);
if (MLS.istable(mtab)) {
SLS.rawgeti(stab, sntmap, id);
assert(SLS.istable(stab));
int tw = sb->total_writes();
sb->write_int32(id);
nmodified += 1;
@@ -367,6 +375,44 @@ void World::diff_tangible_databases(const IdVector &basis, lua_State *master, St
sb->overwrite_int32(write_count_after, nmodified);
}
void World::patch_numbered_tables(StreamBuffer *sb) {
lua_State *L = state();
LuaVar tangibles, ntmap, tab;
LuaStack LS(L, tangibles, ntmap, tab);
LS.rawget(tangibles, LuaRegistry, "tangibles");
LS.rawget(ntmap, LuaRegistry, "ntmap");
assert(LS.istable(tangibles));
assert(LS.istable(ntmap));
int nmodified = sb->read_int32();
for (int i = 0; i < nmodified; i++) {
int index = sb->read_int32();
LS.rawgeti(tab, ntmap, index);
assert(LS.istable(tab));
patch_table(LS, tangibles, ntmap, tab, sb);
}
LS.result();
}
void World::patch_tangible_databases(StreamBuffer *sb) {
lua_State *L = state();
LuaVar tangibles, ntmap, tab;
LuaStack LS(L, tangibles, ntmap, tab);
LS.rawget(tangibles, LuaRegistry, "tangibles");
LS.rawget(ntmap, LuaRegistry, "ntmap");
assert(LS.istable(tangibles));
assert(LS.istable(ntmap));
int nmodified = sb->read_int32();
for (int i = 0; i < nmodified; i++) {
int64_t id = sb->read_int64();
LS.rawgeti(tab, tangibles, id);
assert(LS.istable(tab));
patch_table(LS, tangibles, ntmap, tab, sb);
}
LS.result();
}
LuaDefine(table_diffcompare, "c") {
LuaArg mtnmap, mtab, mstnmap, mstab, stnmap, stab;
LuaRet dbgstring;