Mercurial > prosody-hg
comparison core/configmanager.lua @ 1777:de86734d3f7f
configmanager: Assign a chunk name to config files loaded using the default config loader (fixes issues with some diagnostic tools).
| author | Waqas Hussain <waqas20@gmail.com> |
|---|---|
| date | Sat, 12 Sep 2009 03:45:19 +0500 |
| parents | 0e3eacf135f2 |
| children | 343a9eb7540e 1402615b66f8 |
comparison
equal
deleted
inserted
replaced
| 1776:d4835b79d2ca | 1777:de86734d3f7f |
|---|---|
| 66 format = format or filename:match("%w+$"); | 66 format = format or filename:match("%w+$"); |
| 67 | 67 |
| 68 if parsers[format] and parsers[format].load then | 68 if parsers[format] and parsers[format].load then |
| 69 local f, err = io.open(filename); | 69 local f, err = io.open(filename); |
| 70 if f then | 70 if f then |
| 71 local ok, err = parsers[format].load(f:read("*a")); | 71 local ok, err = parsers[format].load(f:read("*a"), filename); |
| 72 f:close(); | 72 f:close(); |
| 73 if ok then | 73 if ok then |
| 74 eventmanager.fire_event("config-reloaded", { filename = filename, format = format }); | 74 eventmanager.fire_event("config-reloaded", { filename = filename, format = format }); |
| 75 end | 75 end |
| 76 return ok, "parser", err; | 76 return ok, "parser", err; |
| 97 -- Built-in Lua parser | 97 -- Built-in Lua parser |
| 98 do | 98 do |
| 99 local loadstring, pcall, setmetatable = _G.loadstring, _G.pcall, _G.setmetatable; | 99 local loadstring, pcall, setmetatable = _G.loadstring, _G.pcall, _G.setmetatable; |
| 100 local setfenv, rawget, tostring = _G.setfenv, _G.rawget, _G.tostring; | 100 local setfenv, rawget, tostring = _G.setfenv, _G.rawget, _G.tostring; |
| 101 parsers.lua = {}; | 101 parsers.lua = {}; |
| 102 function parsers.lua.load(data) | 102 function parsers.lua.load(data, filename) |
| 103 local env; | 103 local env; |
| 104 -- The ' = true' are needed so as not to set off __newindex when we assign the functions below | 104 -- The ' = true' are needed so as not to set off __newindex when we assign the functions below |
| 105 env = setmetatable({ Host = true; host = true; Component = true, component = true, | 105 env = setmetatable({ Host = true; host = true; Component = true, component = true, |
| 106 Include = true, include = true, RunScript = dofile }, { __index = function (t, k) | 106 Include = true, include = true, RunScript = dofile }, { __index = function (t, k) |
| 107 return rawget(_G, k) or | 107 return rawget(_G, k) or |
| 137 | 137 |
| 138 function env.Include(file) | 138 function env.Include(file) |
| 139 local f, err = io.open(file); | 139 local f, err = io.open(file); |
| 140 if f then | 140 if f then |
| 141 local data = f:read("*a"); | 141 local data = f:read("*a"); |
| 142 local ok, err = parsers.lua.load(data); | 142 local ok, err = parsers.lua.load(data, file); |
| 143 if not ok then error(err:gsub("%[string.-%]", file), 0); end | 143 if not ok then error(err:gsub("%[string.-%]", file), 0); end |
| 144 end | 144 end |
| 145 if not f then error("Error loading included "..file..": "..err, 0); end | 145 if not f then error("Error loading included "..file..": "..err, 0); end |
| 146 return f, err; | 146 return f, err; |
| 147 end | 147 end |
| 148 env.include = env.Include; | 148 env.include = env.Include; |
| 149 | 149 |
| 150 local chunk, err = loadstring(data); | 150 local chunk, err = loadstring(data, "@"..filename); |
| 151 | 151 |
| 152 if not chunk then | 152 if not chunk then |
| 153 return nil, err; | 153 return nil, err; |
| 154 end | 154 end |
| 155 | 155 |
