-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconfig.lib.lua
More file actions
38 lines (34 loc) · 877 Bytes
/
config.lib.lua
File metadata and controls
38 lines (34 loc) · 877 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
-----------------------------------------------------------------------------
-- Midcraft Commander
-- Author: MewK
--
-- This program is released under the MIT License (MIT).
-----------------------------------------------------------------------------
function loadConfig(path, defaultConfig)
-- Load saved config
local savedConfig = {}
if fs.exists(path) then
local file = fs.open(path, 'r')
if file then
local data = file.readAll()
savedConfig = textutils.unserialize(data)
file.close()
else
error('Could not open file')
end
end
-- Merge configs
for name, value in pairs(savedConfig) do
defaultConfig[name] = value
end
return defaultConfig
end
function saveConfig(path, config)
local file = fs.open(path, 'w')
if file then
file.write(textutils.serialize(config))
file.close()
else
error('Could not open file')
end
end