-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.lua
49 lines (42 loc) · 912 Bytes
/
config.lua
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
37
38
39
40
41
42
43
44
45
46
47
48
49
------------------------
-- Configuration keeper
------------------------
local _M = {}
local sep = "/"
if WIN32 then
sep = "\\"
end
local FILENAME = _USERHOME..sep.."spellchecker.conf"
function _M:load()
local handle = io.open(FILENAME, "r")
if not handle then return end
for line in handle:lines()
do
key, val = line:match("([^=]+)=(.+)")
if key then
self[key] = tonumber(val) or val
end
end
handle:close()
end
function _M:save()
local handle = io.open(FILENAME, "w")
if handle then
for key, val in pairs(self)
do
if type(val) == "string" or type(val) == "number" then
handle:write(tostring(key).."="..tostring(val).."\n")
end
end
handle:close()
end
end
local function shutdown()
_M:save()
end
function _M.init()
_M:load()
events.connect(events.RESET_BEFORE, shutdown)
events.connect(events.QUIT, shutdown)
end
return _M