core/configmanager.lua

changeset 3609
954b1159f2f3
parent 3573
f31fa6520a4b
child 3610
2084959d4096
equal deleted inserted replaced
3608:ae0f83feaff4 3609:954b1159f2f3
11 setmetatable, loadfile, pcall, rawget, rawset, io, error, dofile, type, pairs, table, string.format; 11 setmetatable, loadfile, pcall, rawget, rawset, io, error, dofile, type, pairs, table, string.format;
12 12
13 13
14 local fire_event = prosody and prosody.events.fire_event or function () end; 14 local fire_event = prosody and prosody.events.fire_event or function () end;
15 15
16 local path_sep = package.config:sub(1,1);
17
16 module "configmanager" 18 module "configmanager"
17 19
18 local parsers = {}; 20 local parsers = {};
19 21
20 local config_mt = { __index = function (t, k) return rawget(t, "*"); end}; 22 local config_mt = { __index = function (t, k) return rawget(t, "*"); end};
60 return false; 62 return false;
61 end 63 end
62 64
63 function _M.set(host, section, key, value) 65 function _M.set(host, section, key, value)
64 return set(config, host, section, key, value); 66 return set(config, host, section, key, value);
67 end
68
69 -- Helper function to resolve relative paths (needed by config)
70 do
71 local rel_path_start = ".."..path_sep;
72 function resolve_relative_path(parent_path, path)
73 if path then
74 local is_relative;
75 if path_sep == "/" and path:sub(1,1) ~= "/" then
76 is_relative = true;
77 elseif path_sep == "\\" and (path:sub(1,1) ~= "/" and path:sub(2,3) ~= ":\\") then
78 is_relative = true;
79 end
80 if is_relative then
81 return parent_path..path_sep..path;
82 end
83 end
84 return path;
85 end
65 end 86 end
66 87
67 function load(filename, format) 88 function load(filename, format)
68 format = format or filename:match("%w+$"); 89 format = format or filename:match("%w+$");
69 90

mercurial