File: prefs.lua

package info (click to toggle)
instead 1.6.0-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 6,220 kB
  • sloc: ansic: 26,619; makefile: 247; sh: 207; cpp: 93
file content (36 lines) | stat: -rw-r--r-- 767 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
prefs = obj {
	nam = 'preferences',
	system_type = true,
	load = function(s)
		local name = get_savepath() .. '/prefs';
		local f, err = loadfile(name);
		if not f then return nil end
		f();
	end,
	ini = function(s)
		return s:load()
	end,
	store = function(s)
		local name = get_savepath() .. '/prefs';
		local h = stead.io.open(name,"w");
		if not h then return false end
		stead.savemembers(h, s, 'prefs', true);
		h:flush();
		h:close();
	end,
	save = function(s) -- save prefs on every save
		s:store()
	end,
	purge = function(s)
		local name = get_savepath() .. '/prefs';
		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
		return stead.os.remove(name);
	end
};

-- vim:ts=4