From 609933799faff0ab425cb6188c5716a0333c53d8 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 29 Jan 2009 02:13:30 +0000 Subject: configmanager: Add support for defining components --- core/configmanager.lua | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'core/configmanager.lua') diff --git a/core/configmanager.lua b/core/configmanager.lua index a6e86347..a50e7223 100644 --- a/core/configmanager.lua +++ b/core/configmanager.lua @@ -107,7 +107,8 @@ do parsers.lua = {}; function parsers.lua.load(data) local env; - env = setmetatable({ Host = true; host = true; }, { __index = function (t, k) + -- The ' = true' are needed so as not to set off __newindex when we assign the functions below + env = setmetatable({ Host = true; host = true; Component = true, component = true }, { __index = function (t, k) return rawget(_G, k) or function (settings_table) config[__currenthost or "*"][k] = settings_table; @@ -119,10 +120,21 @@ do function env.Host(name) rawset(env, "__currenthost", name); + -- Needs at least one setting to logically exist :) set(name or "*", "core", "defined", true); end env.host = env.Host; + function env.Component(name) + return function (module) + set(name, "core", "component_module", module); + -- Don't load the global modules by default + set(name, "core", "modules_enable", false); + rawset(env, "__currenthost", name); + end + end + env.component = env.Component; + local chunk, err = loadstring(data); if not chunk then -- cgit v1.2.3