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