Commit 62ceadb0 authored by Marek Vavruša's avatar Marek Vavruša

daemon/lua: made ‘modules’ append-only

this makes some services append-only, so the configuration
can look like:

modules = {
   cache = ‘’,
   hints = true,
}

without wiping previously-set modules
parent a8d056ca
-- Syntactic sugar for module loading
-- `modules.<name> = <config>`
local modules_mt = {
setmetatable(modules, {
__newindex = function (t,k,v)
modules.load(k)
_G[k]['config'](v)
if _G[k] then
local config_call = _G[k]['config']
if config_call and config_call[''] then
config_call(v)
end
end
end
}
setmetatable(modules, modules_mt)
\ No newline at end of file
})
-- Some services are append-only
function protect(defined)
local __protected = { ['modules'] = true }
return setmetatable({}, {
__index = defined,
__newindex = function (t, k, v)
if __protected[k] then
for k2,v2 in pairs(v) do
defined[k][k2] = v2
end
else
defined[k] = v
end
end
})
end
_G = protect(getfenv(0))
setfenv(0, _G)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment