101 local setfenv, rawget, tostring = _G.setfenv, _G.rawget, _G.tostring; |
101 local setfenv, rawget, tostring = _G.setfenv, _G.rawget, _G.tostring; |
102 parsers.lua = {}; |
102 parsers.lua = {}; |
103 function parsers.lua.load(data, filename) |
103 function parsers.lua.load(data, filename) |
104 local env; |
104 local env; |
105 -- The ' = true' are needed so as not to set off __newindex when we assign the functions below |
105 -- The ' = true' are needed so as not to set off __newindex when we assign the functions below |
106 env = setmetatable({ Host = true; host = true; Component = true, component = true, |
106 env = setmetatable({ Host = true, host = true, VirtualHost = true, Component = true, component = true, |
107 Include = true, include = true, RunScript = dofile }, { __index = function (t, k) |
107 Include = true, include = true, RunScript = dofile }, { __index = function (t, k) |
108 return rawget(_G, k) or |
108 return rawget(_G, k) or |
109 function (settings_table) |
109 function (settings_table) |
110 config[__currenthost or "*"][k] = settings_table; |
110 config[__currenthost or "*"][k] = settings_table; |
111 end; |
111 end; |
113 __newindex = function (t, k, v) |
113 __newindex = function (t, k, v) |
114 set(env.__currenthost or "*", "core", k, v); |
114 set(env.__currenthost or "*", "core", k, v); |
115 end}); |
115 end}); |
116 |
116 |
117 rawset(env, "__currenthost", "*") -- Default is global |
117 rawset(env, "__currenthost", "*") -- Default is global |
118 function env.Host(name) |
118 function env.VirtualHost(name) |
119 if rawget(config, name) and rawget(config[name].core, "component_module") then |
119 if rawget(config, name) and rawget(config[name].core, "component_module") then |
120 error(format("Host %q clashes with previously defined %s Component %q, for services use a sub-domain like conference.%s", |
120 error(format("Host %q clashes with previously defined %s Component %q, for services use a sub-domain like conference.%s", |
121 name, config[name].core.component_module:gsub("^%a+$", { component = "external", muc = "MUC"}), name, name), 0); |
121 name, config[name].core.component_module:gsub("^%a+$", { component = "external", muc = "MUC"}), name, name), 0); |
122 end |
122 end |
123 rawset(env, "__currenthost", name); |
123 rawset(env, "__currenthost", name); |
124 -- Needs at least one setting to logically exist :) |
124 -- Needs at least one setting to logically exist :) |
125 set(name or "*", "core", "defined", true); |
125 set(name or "*", "core", "defined", true); |
126 end |
126 end |
127 env.host = env.Host; |
127 env.Host, env.host = env.VirtualHost, env.VirtualHost; |
128 |
128 |
129 function env.Component(name) |
129 function env.Component(name) |
130 if rawget(config, name) and rawget(config[name].core, "defined") and not rawget(config[name].core, "component_module") then |
130 if rawget(config, name) and rawget(config[name].core, "defined") and not rawget(config[name].core, "component_module") then |
131 error(format("Component %q clashes with previously defined Host %q, for services use a sub-domain like conference.%s", |
131 error(format("Component %q clashes with previously defined Host %q, for services use a sub-domain like conference.%s", |
132 name, name, name), 0); |
132 name, name, name), 0); |