Software / code / prosody
Comparison
core/configmanager.lua @ 3610:2084959d4096
configmanager: Update Include and RunScript directives to support paths relative to the (current!) config file
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Wed, 10 Nov 2010 19:50:07 +0000 |
| parent | 3609:954b1159f2f3 |
| child | 3613:f617718d2221 |
comparison
equal
deleted
inserted
replaced
| 3609:954b1159f2f3 | 3610:2084959d4096 |
|---|---|
| 143 local env; | 143 local env; |
| 144 -- The ' = true' are needed so as not to set off __newindex when we assign the functions below | 144 -- The ' = true' are needed so as not to set off __newindex when we assign the functions below |
| 145 env = setmetatable({ | 145 env = setmetatable({ |
| 146 Host = true, host = true, VirtualHost = true, | 146 Host = true, host = true, VirtualHost = true, |
| 147 Component = true, component = true, | 147 Component = true, component = true, |
| 148 Include = true, include = true, RunScript = dofile }, { | 148 Include = true, include = true, RunScript = true }, { |
| 149 __index = function (t, k) | 149 __index = function (t, k) |
| 150 return rawget(_G, k) or | 150 return rawget(_G, k) or |
| 151 function (settings_table) | 151 function (settings_table) |
| 152 config[__currenthost or "*"][k] = settings_table; | 152 config[__currenthost or "*"][k] = settings_table; |
| 153 end; | 153 end; |
| 203 | 203 |
| 204 function env.Include(file) | 204 function env.Include(file) |
| 205 local f, err = io.open(file); | 205 local f, err = io.open(file); |
| 206 if f then | 206 if f then |
| 207 local data = f:read("*a"); | 207 local data = f:read("*a"); |
| 208 local file = resolve_relative_path(filename:gsub("[^"..path_sep.."]+$", ""), file); | |
| 208 local ok, err = parsers.lua.load(data, file); | 209 local ok, err = parsers.lua.load(data, file); |
| 209 if not ok then error(err:gsub("%[string.-%]", file), 0); end | 210 if not ok then error(err:gsub("%[string.-%]", file), 0); end |
| 210 end | 211 end |
| 211 if not f then error("Error loading included "..file..": "..err, 0); end | 212 if not f then error("Error loading included "..file..": "..err, 0); end |
| 212 return f, err; | 213 return f, err; |
| 213 end | 214 end |
| 214 env.include = env.Include; | 215 env.include = env.Include; |
| 215 | 216 |
| 217 function env.RunScript(file) | |
| 218 return dofile(resolve_relative_path(filename:gsub("[^"..path_sep.."]+$", ""), file)); | |
| 219 end | |
| 220 | |
| 216 local chunk, err = loadstring(data, "@"..filename); | 221 local chunk, err = loadstring(data, "@"..filename); |
| 217 | 222 |
| 218 if not chunk then | 223 if not chunk then |
| 219 return nil, err; | 224 return nil, err; |
| 220 end | 225 end |