steed/stead/prefs.lua

37 lines
761 B
Lua
Raw Normal View History

2010-06-19 13:14:25 +03:00
prefs = obj {
nam = 'preferences',
2010-07-22 13:39:48 +03:00
system_type = true,
2010-07-24 14:50:56 +03:00
load = function(s)
2010-06-19 13:14:25 +03:00
local name = get_savepath() .. '/prefs';
local f, err = loadfile(name);
if not f then return nil end
f();
end,
2010-07-24 14:50:56 +03:00
ini = function(s)
return s:load()
end,
2010-06-19 13:14:25 +03:00
store = function(s)
local name = get_savepath() .. '/prefs';
local h = stead.io.open(name,"w");
if not h then return false end
savemembers(h, s, 'prefs', true);
h:flush();
h:close();
end,
2011-04-23 20:54:56 +03:00
save = function(s) -- save prefs on every save
s:store()
2010-07-24 15:02:49 +03:00
end,
2010-06-19 13:14:25 +03:00
purge = function(s)
local name = get_savepath() .. '/prefs';
2010-10-30 15:54:41 +03:00
local k,v
for k,v in pairs(s) do
if type(v) ~= 'function' and k ~= 'nam' and k ~= 'system_type' then
s[k] = nil
end
end
2010-06-19 13:14:25 +03:00
return stead.os.remove(name);
end
};
2010-07-06 13:15:27 +03:00
-- vim:ts=4