Software /
code /
prosody
Comparison
core/configmanager.lua @ 3613:f617718d2221
configmanager: Change parser API again to pass a config table to insert settings to. Fixes Include(). (Thanks Zash/answerman)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 11 Nov 2010 12:23:51 +0000 |
parent | 3610:2084959d4096 |
child | 3780:791aede977da |
comparison
equal
deleted
inserted
replaced
3612:5547acd18a9f | 3613:f617718d2221 |
---|---|
89 format = format or filename:match("%w+$"); | 89 format = format or filename:match("%w+$"); |
90 | 90 |
91 if parsers[format] and parsers[format].load then | 91 if parsers[format] and parsers[format].load then |
92 local f, err = io.open(filename); | 92 local f, err = io.open(filename); |
93 if f then | 93 if f then |
94 local new_config, err = parsers[format].load(f:read("*a"), filename); | 94 local new_config = setmetatable({ ["*"] = { core = {} } }, config_mt); |
95 local ok, err = parsers[format].load(f:read("*a"), filename, new_config); | |
95 f:close(); | 96 f:close(); |
96 if new_config then | 97 if ok then |
97 setmetatable(new_config, config_mt); | |
98 config = new_config; | 98 config = new_config; |
99 fire_event("config-reloaded", { | 99 fire_event("config-reloaded", { |
100 filename = filename, | 100 filename = filename, |
101 format = format, | 101 format = format, |
102 config = config | 102 config = config |
135 -- Built-in Lua parser | 135 -- Built-in Lua parser |
136 do | 136 do |
137 local loadstring, pcall, setmetatable = _G.loadstring, _G.pcall, _G.setmetatable; | 137 local loadstring, pcall, setmetatable = _G.loadstring, _G.pcall, _G.setmetatable; |
138 local setfenv, rawget, tostring = _G.setfenv, _G.rawget, _G.tostring; | 138 local setfenv, rawget, tostring = _G.setfenv, _G.rawget, _G.tostring; |
139 parsers.lua = {}; | 139 parsers.lua = {}; |
140 function parsers.lua.load(data, filename) | 140 function parsers.lua.load(data, filename, config) |
141 local config = { ["*"] = { core = {} } }; | |
142 | |
143 local env; | 141 local env; |
144 -- The ' = true' are needed so as not to set off __newindex when we assign the functions below | 142 -- The ' = true' are needed so as not to set off __newindex when we assign the functions below |
145 env = setmetatable({ | 143 env = setmetatable({ |
146 Host = true, host = true, VirtualHost = true, | 144 Host = true, host = true, VirtualHost = true, |
147 Component = true, component = true, | 145 Component = true, component = true, |
204 function env.Include(file) | 202 function env.Include(file) |
205 local f, err = io.open(file); | 203 local f, err = io.open(file); |
206 if f then | 204 if f then |
207 local data = f:read("*a"); | 205 local data = f:read("*a"); |
208 local file = resolve_relative_path(filename:gsub("[^"..path_sep.."]+$", ""), file); | 206 local file = resolve_relative_path(filename:gsub("[^"..path_sep.."]+$", ""), file); |
209 local ok, err = parsers.lua.load(data, file); | 207 local ret, err = parsers.lua.load(data, file, config); |
210 if not ok then error(err:gsub("%[string.-%]", file), 0); end | 208 if not ret then error(err:gsub("%[string.-%]", file), 0); end |
211 end | 209 end |
212 if not f then error("Error loading included "..file..": "..err, 0); end | 210 if not f then error("Error loading included "..file..": "..err, 0); end |
213 return f, err; | 211 return f, err; |
214 end | 212 end |
215 env.include = env.Include; | 213 env.include = env.Include; |
230 | 228 |
231 if not ok then | 229 if not ok then |
232 return nil, err; | 230 return nil, err; |
233 end | 231 end |
234 | 232 |
235 return config; | 233 return true; |
236 end | 234 end |
237 | 235 |
238 end | 236 end |
239 | 237 |
240 return _M; | 238 return _M; |