Changeset

750:fbfcf8c1c830

configmanager: Add support for defining components
author Matthew Wild <mwild1@gmail.com>
date Thu, 29 Jan 2009 02:13:30 +0000
parents 749:1359492f45d7
children 751:7c22619fdb19
files core/configmanager.lua
diffstat 1 files changed, 13 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/core/configmanager.lua	Thu Jan 29 02:09:53 2009 +0000
+++ b/core/configmanager.lua	Thu Jan 29 02:13:30 2009 +0000
@@ -107,7 +107,8 @@
 	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 @@
 		
 		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