summaryrefslogtreecommitdiff
path: root/lib/clod.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lib/clod.lua')
-rw-r--r--lib/clod.lua35
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/clod.lua b/lib/clod.lua
index d25048b..7058ab3 100644
--- a/lib/clod.lua
+++ b/lib/clod.lua
@@ -12,12 +12,47 @@ local loadstring = loadstring
local tconcat = table.concat
local setmetatable = setmetatable
local setfenv = setfenv
+local pairs = pairs
-- metatable for clod config operations
local clod_mt = {}
-- metadata for clod config instances
local metadata = setmetatable({}, {__mode = "k"})
+-- metatable for settings objects
+local settings_mt = {}
+local gen_settings
+
+function settings_mt:__index(subkey)
+ local meta = metadata[self]
+ local confmeta = metadata[meta.conf]
+ local key = subkey
+ if meta.prefix then
+ key = meta.prefix .. "." .. subkey
+ end
+ if confmeta.settings[key] then
+ return confmeta.settings[key].value
+ end
+ for k in pairs(confmeta.settings) do
+ if k:sub(1,#key) == key then
+ return gen_settings(self, key)
+ end
+ end
+end
+
+-- Helper routines
+function gen_settings(tab, prefix)
+ local meta = metadata[tab]
+ local clodconf = meta.conf or tab
+ local newmeta = {
+ conf = clodconf,
+ prefix = prefix
+ }
+ local ret = setmetatable({}, settings_mt)
+ metadata[ret] = newmeta
+ return ret
+end
+
-- Methods for clod instances
local methods = {}