Comparison

core/configmanager.lua @ 3011:1189a29cd846

configmanager: Add VirtualHost as an alias for Host (re-applied in trunk due to previous bad merge with 0.7)
author Matthew Wild <mwild1@gmail.com>
date Wed, 14 Apr 2010 12:59:46 +0100
parent 2925:692b3c6c5bd2
child 3012:6d86e26f0923
comparison
equal deleted inserted replaced
2973:61e103d99578 3011:1189a29cd846
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);