-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathconfig
More file actions
38 lines (34 loc) · 652 Bytes
/
Copy pathconfig
File metadata and controls
38 lines (34 loc) · 652 Bytes
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
local config = {}
local current_file = nil
function init(file)
if file then
if fs.exists(file) then
local f = fs.open(file, "r")
local data = f.readAll()
f.close()
local c = textutils.unserialize(data)
if c then config = c else config = {} end
current_file = file
else
config = {}
current_file = file
end
else
config = {}
current_file = nil
end
end
local function save()
if current_file then
local f = fs.open(current_file, "w")
f.write(textutils.serialize(config))
f.close()
end
end
function get(key, default)
return config[key] or default
end
function set(key, value)
config[key] = value
save()
end