opus/sys/modules/opus/config.lua

33 lines
600 B
Lua
Raw Normal View History

local Util = require('opus.util')
2016-12-11 19:24:52 +00:00
2018-01-04 08:30:59 +00:00
local fs = _G.fs
2017-10-08 21:45:01 +00:00
2016-12-11 19:24:52 +00:00
local Config = { }
2018-01-04 08:30:59 +00:00
function Config.load(fname, data)
2017-05-20 22:27:26 +00:00
local filename = 'usr/config/' .. fname
2018-12-23 03:11:16 +00:00
data = data or { }
2016-12-11 19:24:52 +00:00
2017-05-20 22:27:26 +00:00
if not fs.exists('usr/config') then
2018-01-24 22:39:38 +00:00
fs.makeDir('usr/config')
2016-12-11 19:24:52 +00:00
end
if not fs.exists(filename) then
2018-01-24 22:39:38 +00:00
Util.writeTable(filename, data)
2016-12-11 19:24:52 +00:00
else
2018-10-21 08:46:40 +00:00
local contents = Util.readTable(filename) or
error('Configuration file is corrupt:' .. filename)
Util.merge(data, contents)
2016-12-11 19:24:52 +00:00
end
2018-11-09 20:07:55 +00:00
return data
2016-12-11 19:24:52 +00:00
end
2018-01-04 08:30:59 +00:00
function Config.update(fname, data)
2017-05-20 22:27:26 +00:00
local filename = 'usr/config/' .. fname
2016-12-11 19:24:52 +00:00
Util.writeTable(filename, data)
end
2018-01-04 08:30:59 +00:00
return Config