summaryrefslogtreecommitdiff
path: root/script/config/config.lua
diff options
context:
space:
mode:
Diffstat (limited to 'script/config/config.lua')
-rw-r--r--script/config/config.lua20
1 files changed, 18 insertions, 2 deletions
diff --git a/script/config/config.lua b/script/config/config.lua
index 61b09f4e..e7831707 100644
--- a/script/config/config.lua
+++ b/script/config/config.lua
@@ -203,13 +203,19 @@ local Template = {
local config = {}
local rawConfig = {}
+local m = {}
+m.watchList = {}
+
local function update(key, value, raw)
+ local oldValue = config[key]
+ if util.equal(oldValue, value) then
+ return
+ end
config[key] = value
rawConfig[key] = raw
+ m.event('update', key, value, oldValue)
end
-local m = {}
-
function m.set(key, value)
local unit = Template[key]
if not unit then
@@ -285,6 +291,16 @@ function m.update(new)
expand(new)
end
+function m.watch(callback)
+ m.watchList[#m.watchList+1] = callback
+end
+
+function m.event(ev, ...)
+ for _, callback in ipairs(m.watchList) do
+ callback(ev, ...)
+ end
+end
+
for key in pairs(Template) do
m.set(key)
end