Mercurial > prosody-hg
comparison core/configmanager.lua @ 6718:be98ebe87eef
configmanager: Refactor function to avoid re-declaring local variable [luacheck]
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Mon, 18 May 2015 19:07:31 +0100 |
| parents | 4fecfc81dac1 |
| children | 6236668da30a |
comparison
equal
deleted
inserted
replaced
| 6717:4fecfc81dac1 | 6718:be98ebe87eef |
|---|---|
| 181 end | 181 end |
| 182 end | 182 end |
| 183 env.component = env.Component; | 183 env.component = env.Component; |
| 184 | 184 |
| 185 function env.Include(file) | 185 function env.Include(file) |
| 186 -- Check whether this is a wildcard Include | |
| 186 if file:match("[*?]") then | 187 if file:match("[*?]") then |
| 187 local lfs = deps.softreq "lfs"; | 188 local lfs = deps.softreq "lfs"; |
| 188 if not lfs then | 189 if not lfs then |
| 189 error(format("Error expanding wildcard pattern in Include %q - LuaFileSystem not available", file)); | 190 error(format("Error expanding wildcard pattern in Include %q - LuaFileSystem not available", file)); |
| 190 end | 191 end |
| 200 for f in lfs.dir(path) do | 201 for f in lfs.dir(path) do |
| 201 if f:sub(1,1) ~= "." and f:match(patt) then | 202 if f:sub(1,1) ~= "." and f:match(patt) then |
| 202 env.Include(path..path_sep..f); | 203 env.Include(path..path_sep..f); |
| 203 end | 204 end |
| 204 end | 205 end |
| 205 else | 206 return; |
| 206 local file = resolve_relative_path(config_file:gsub("[^"..path_sep.."]+$", ""), file); | 207 end |
| 207 local f, err = io.open(file); | 208 -- Not a wildcard, so resolve (potentially) relative path and run through config parser |
| 208 if f then | 209 file = resolve_relative_path(config_file:gsub("[^"..path_sep.."]+$", ""), file); |
| 209 local ret, err = parsers.lua.load(f:read("*a"), file, config); | 210 local f, err = io.open(file); |
| 210 if not ret then error(err:gsub("%[string.-%]", file), 0); end | 211 if f then |
| 211 end | 212 local ret, err = parsers.lua.load(f:read("*a"), file, config_table); |
| 212 if not f then error("Error loading included "..file..": "..err, 0); end | 213 if not ret then error(err:gsub("%[string.-%]", file), 0); end |
| 213 return f, err; | 214 end |
| 214 end | 215 if not f then error("Error loading included "..file..": "..err, 0); end |
| 216 return f, err; | |
| 215 end | 217 end |
| 216 env.include = env.Include; | 218 env.include = env.Include; |
| 217 | 219 |
| 218 function env.RunScript(file) | 220 function env.RunScript(file) |
| 219 return dofile(resolve_relative_path(config_file:gsub("[^"..path_sep.."]+$", ""), file)); | 221 return dofile(resolve_relative_path(config_file:gsub("[^"..path_sep.."]+$", ""), file)); |
