Comparison

core/configmanager.lua @ 2984:3094166cfdd5

Merge 0.6 into 0.7.
author Waqas Hussain <waqas20@gmail.com>
date Sat, 01 May 2010 05:18:38 +0500
parent 2925:692b3c6c5bd2
parent 2980:9f593650b3ce
child 2985:fde53d82fde0
comparison
equal deleted inserted replaced
2978:5760074dc7d4 2984:3094166cfdd5
110 local setfenv, rawget, tostring = _G.setfenv, _G.rawget, _G.tostring; 110 local setfenv, rawget, tostring = _G.setfenv, _G.rawget, _G.tostring;
111 parsers.lua = {}; 111 parsers.lua = {};
112 function parsers.lua.load(data, filename) 112 function parsers.lua.load(data, filename)
113 local env; 113 local env;
114 -- The ' = true' are needed so as not to set off __newindex when we assign the functions below 114 -- The ' = true' are needed so as not to set off __newindex when we assign the functions below
115 env = setmetatable({ Host = true; host = true; Component = true, component = true, 115 env = setmetatable({ Host = true, host = true, VirtualHost = true, Component = true, component = true,
116 Include = true, include = true, RunScript = dofile }, { __index = function (t, k) 116 Include = true, include = true, RunScript = dofile }, { __index = function (t, k)
117 return rawget(_G, k) or 117 return rawget(_G, k) or
118 function (settings_table) 118 function (settings_table)
119 config[__currenthost or "*"][k] = settings_table; 119 config[__currenthost or "*"][k] = settings_table;
120 end; 120 end;
122 __newindex = function (t, k, v) 122 __newindex = function (t, k, v)
123 set(env.__currenthost or "*", "core", k, v); 123 set(env.__currenthost or "*", "core", k, v);
124 end}); 124 end});
125 125
126 rawset(env, "__currenthost", "*") -- Default is global 126 rawset(env, "__currenthost", "*") -- Default is global
127 function env.Host(name) 127 function env.VirtualHost(name)
128 if rawget(config, name) and rawget(config[name].core, "component_module") then 128 if rawget(config, name) and rawget(config[name].core, "component_module") then
129 error(format("Host %q clashes with previously defined %s Component %q, for services use a sub-domain like conference.%s", 129 error(format("Host %q clashes with previously defined %s Component %q, for services use a sub-domain like conference.%s",
130 name, config[name].core.component_module:gsub("^%a+$", { component = "external", muc = "MUC"}), name, name), 0); 130 name, config[name].core.component_module:gsub("^%a+$", { component = "external", muc = "MUC"}), name, name), 0);
131 end 131 end
132 rawset(env, "__currenthost", name); 132 rawset(env, "__currenthost", name);
133 -- Needs at least one setting to logically exist :) 133 -- Needs at least one setting to logically exist :)
134 set(name or "*", "core", "defined", true); 134 set(name or "*", "core", "defined", true);
135 end 135 end
136 env.host = env.Host; 136 env.Host, env.host = env.VirtualHost, env.VirtualHost;
137 137
138 function env.Component(name) 138 function env.Component(name)
139 if rawget(config, name) and rawget(config[name].core, "defined") and not rawget(config[name].core, "component_module") then 139 if rawget(config, name) and rawget(config[name].core, "defined") and not rawget(config[name].core, "component_module") then
140 error(format("Component %q clashes with previously defined Host %q, for services use a sub-domain like conference.%s", 140 error(format("Component %q clashes with previously defined Host %q, for services use a sub-domain like conference.%s",
141 name, name, name), 0); 141 name, name, name), 0);