more clever save

This commit is contained in:
p.kosyh 2010-06-20 14:05:49 +00:00
parent 95b192d51e
commit ac863531be

View file

@ -1320,7 +1320,6 @@ function do_ini(self)
for_each(game, "game", check_list, isList) for_each(game, "game", check_list, isList)
stead.fixups:apply();
for_each_object(call_ini); for_each_object(call_ini);
me():tag(); me():tag();
@ -1444,7 +1443,7 @@ function savemembers(h, self, name, need)
end end
if type(k) == 'string' then if type(k) == 'string' then
savevar(h, v, name..'["'..k:gsub('"','\\"')..'"]', need or need2); savevar(h, v, name..'['..stead.string.format("%q",k)..']', need or need2);
else else
savevar(h, v, name.."["..k.."]", need or need2) savevar(h, v, name.."["..k.."]", need or need2)
end end
@ -1478,8 +1477,7 @@ function savevar (h, v, n, need)
if type(v.key_name) == 'string' and v.key_name ~= n and if type(v.key_name) == 'string' and v.key_name ~= n and
'_G["'..v.key_name..'"]' ~= n then -- just xref '_G["'..v.key_name..'"]' ~= n then -- just xref
if need then if need then
local w = stead.string.format("%s = ref(%q)", n, v.key_name); h:write(stead.string.format("%s = %s\n", n, v.key_name));
h:write(stead.string.format("%s = stead.fixups:add(%q)\n", n, w));
end end
return return
end end
@ -1538,6 +1536,7 @@ function game_save(self, name, file)
if type(n) == 'string' and n ~= "" then if type(n) == 'string' and n ~= "" then
h:write("-- $Name: "..n:gsub("\n","\\n").."$\n"); h:write("-- $Name: "..n:gsub("\n","\\n").."$\n");
end end
save_object('allocator', allocator, h); -- always first!
for_each_object(save_object, h); for_each_object(save_object, h);
save_object('game', self, h); save_object('game', self, h);
save_object('_G', _G, h); save_object('_G', _G, h);
@ -1920,25 +1919,6 @@ function delete(v)
allocator:delete(v); allocator:delete(v);
end end
stead.fixups = {
fix = {},
apply = function(s)
local i,v
for i,v in ipairs(s.fix) do
local f = loadstring(v);
if type(f) ~= 'function' then
error ("Error while fixup:" .. tostring(v))
end
f();
end
s.fix = {}
end,
add = function(s, str)
stead.table.insert(s.fix, str)
return nil
end
}
timer = obj { -- timer calls stead.timer callback timer = obj { -- timer calls stead.timer callback
nam = 'timer', nam = 'timer',
ini = function(s) ini = function(s)