Added luasnap checkpointing mechanism
This commit is contained in:
@@ -34,42 +34,9 @@ util::stringvec read_control_lst(const std::string &path) {
|
||||
|
||||
LuaDefine(source_makeclass, "f") {
|
||||
LuaArg classname;
|
||||
LuaVar action, gname;
|
||||
LuaRet classtab;
|
||||
LuaStack LS(L, classname, classtab, action, gname);
|
||||
|
||||
LS.checkstring(classname);
|
||||
|
||||
// Special case: if the classname is _G, return global env.
|
||||
LS.set(gname, "_G");
|
||||
if (LS.equal(classname, gname)) {
|
||||
LS.set(classtab, LuaGlobals);
|
||||
return LS.result();
|
||||
}
|
||||
|
||||
// Get the classtab from the global environment.
|
||||
// Create it if it doesn't exist.
|
||||
LS.rawget(classtab, LuaGlobals, classname);
|
||||
if (LS.isnil(classtab)) {
|
||||
LS.newtable(classtab);
|
||||
LS.rawset(LuaGlobals, classname, classtab);
|
||||
}
|
||||
|
||||
// If the name isn't bound to a table, abort.
|
||||
if (!LS.istable(classtab)) {
|
||||
luaL_error(L, "%s is not a class", LS.ckstring(classname).c_str());
|
||||
}
|
||||
|
||||
// Repair the special fields.
|
||||
LS.setfield(classtab, "__index", classtab);
|
||||
LS.setfield(classtab, "__class", classname);
|
||||
|
||||
// Repair the action table.
|
||||
LS.getfield(action, classtab, "action");
|
||||
if (!LS.istable(action)) {
|
||||
LS.setfield(classtab, "action", LuaNewTable);
|
||||
}
|
||||
|
||||
LuaStack LS(L, classname, classtab);
|
||||
LS.makeclass(classtab, classname);
|
||||
return LS.result();
|
||||
}
|
||||
|
||||
@@ -200,26 +167,17 @@ void SourceDB::update() {
|
||||
}
|
||||
|
||||
// Delete everything from the global environment except
|
||||
// the class tables and the class action tables.
|
||||
// the class tables.
|
||||
//
|
||||
static void source_clear_globals(lua_State *L) {
|
||||
LuaVar classname, classtab, action, key;
|
||||
LuaStack LS(L, classname, classtab, action, key);
|
||||
LuaVar classname, classtab, key;
|
||||
LuaStack LS(L, classname, classtab, key);
|
||||
|
||||
LS.setfield(LuaGlobals, "_G", LuaNil);
|
||||
LS.set(classname, LuaNil);
|
||||
while (LS.next(LuaGlobals, classname, classtab) != 0) {
|
||||
if (LS.istable(classtab)) {
|
||||
bool keep_action = false;
|
||||
LS.getfield(action, classtab, "action");
|
||||
if (LS.istable(action)) {
|
||||
LS.call(table_clear, action);
|
||||
keep_action = true;
|
||||
}
|
||||
LS.call(table_clear, classtab);
|
||||
if (keep_action) {
|
||||
LS.setfield(classtab, "action", action);
|
||||
}
|
||||
} else {
|
||||
LS.rawset(LuaGlobals, classname, LuaNil);
|
||||
}
|
||||
@@ -239,7 +197,7 @@ static void source_restore_builtins(lua_State *L) {
|
||||
LS.set(key, LuaNil);
|
||||
while (LS.next(snapshot, key, value) != 0) {
|
||||
LS.checktable(value);
|
||||
LS.call(subglobal, source_makeclass, key);
|
||||
LS.makeclass(subglobal, key);
|
||||
LS.set(skey, LuaNil);
|
||||
while (LS.next(value, skey, svalue) != 0) {
|
||||
LS.rawset(subglobal, skey, svalue);
|
||||
|
||||
Reference in New Issue
Block a user