- env = setmetatable({ Host = true; host = true; }, { __index = function (t, k)
- return rawget(_G, k) or
- function (settings_table)
- config[__currenthost or "*"][k] = settings_table;
- end;
- end,
- __newindex = function (t, k, v)
- set(env.__currenthost or "*", "core", k, v);
- end});
+ -- The ' = true' are needed so as not to set off __newindex when we assign the functions below
+ env = setmetatable({
+ Host = true, host = true, VirtualHost = true,
+ Component = true, component = true,
+ Include = true, include = true, RunScript = true }, {
+ __index = function (t, k)
+ return rawget(_G, k) or
+ function (settings_table)
+ config[__currenthost or "*"][k] = settings_table;
+ end;
+ end,
+ __newindex = function (t, k, v)
+ set(config, env.__currenthost or "*", "core", k, v);
+ end
+ });
+
+ rawset(env, "__currenthost", "*") -- Default is global
+ function env.VirtualHost(name)
+ if rawget(config, name) and rawget(config[name].core, "component_module") then
+ error(format("Host %q clashes with previously defined %s Component %q, for services use a sub-domain like conference.%s",
+ name, config[name].core.component_module:gsub("^%a+$", { component = "external", muc = "MUC"}), name, name), 0);
+ end
+ rawset(env, "__currenthost", name);
+ -- Needs at least one setting to logically exist :)
+ set(config, name or "*", "core", "defined", true);
+ return function (config_options)
+ rawset(env, "__currenthost", "*"); -- Return to global scope
+ for option_name, option_value in pairs(config_options) do
+ set(config, name or "*", "core", option_name, option_value);
+ end
+ end;
+ end
+ env.Host, env.host = env.VirtualHost, env.VirtualHost;