Software /
code /
prosody
Comparison
core/configmanager.lua @ 6713:b628870b1bd6
configmanager: Rename variable to avoid name conflict [luacheck]
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 18 May 2015 19:04:37 +0100 |
parent | 6712:29d5875ae38d |
child | 6714:429068c24ea0 |
comparison
equal
deleted
inserted
replaced
6712:29d5875ae38d | 6713:b628870b1bd6 |
---|---|
71 key, value = value, _oldvalue; --COMPAT with code that still uses "core" | 71 key, value = value, _oldvalue; --COMPAT with code that still uses "core" |
72 end | 72 end |
73 return set(config, host, key, value); | 73 return set(config, host, key, value); |
74 end | 74 end |
75 | 75 |
76 function load(filename, format) | 76 function load(filename, config_format) |
77 format = format or filename:match("%w+$"); | 77 config_format = config_format or filename:match("%w+$"); |
78 | 78 |
79 if parsers[format] and parsers[format].load then | 79 if parsers[config_format] and parsers[config_format].load then |
80 local f, err = io.open(filename); | 80 local f, err = io.open(filename); |
81 if f then | 81 if f then |
82 local new_config = setmetatable({ ["*"] = { } }, config_mt); | 82 local new_config = setmetatable({ ["*"] = { } }, config_mt); |
83 local ok, err = parsers[format].load(f:read("*a"), filename, new_config); | 83 local ok, err = parsers[config_format].load(f:read("*a"), filename, new_config); |
84 f:close(); | 84 f:close(); |
85 if ok then | 85 if ok then |
86 config = new_config; | 86 config = new_config; |
87 fire_event("config-reloaded", { | 87 fire_event("config-reloaded", { |
88 filename = filename, | 88 filename = filename, |
89 format = format, | 89 format = config_format, |
90 config = config | 90 config = config |
91 }); | 91 }); |
92 end | 92 end |
93 return ok, "parser", err; | 93 return ok, "parser", err; |
94 end | 94 end |
95 return f, "file", err; | 95 return f, "file", err; |
96 end | 96 end |
97 | 97 |
98 if not format then | 98 if not config_format then |
99 return nil, "file", "no parser specified"; | 99 return nil, "file", "no parser specified"; |
100 else | 100 else |
101 return nil, "file", "no parser for "..(format); | 101 return nil, "file", "no parser for "..(config_format); |
102 end | 102 end |
103 end | 103 end |
104 | 104 |
105 function save(filename, format) | 105 function addparser(config_format, parser) |
106 end | 106 if config_format and parser then |
107 | 107 parsers[config_format] = parser; |
108 function addparser(format, parser) | |
109 if format and parser then | |
110 parsers[format] = parser; | |
111 end | 108 end |
112 end | 109 end |
113 | 110 |
114 -- _M needed to avoid name clash with local 'parsers' | 111 -- _M needed to avoid name clash with local 'parsers' |
115 function _M.parsers() | 112 function _M.parsers() |
116 local p = {}; | 113 local p = {}; |
117 for format in pairs(parsers) do | 114 for config_format in pairs(parsers) do |
118 table.insert(p, format); | 115 table.insert(p, config_format); |
119 end | 116 end |
120 return p; | 117 return p; |
121 end | 118 end |
122 | 119 |
123 -- Built-in Lua parser | 120 -- Built-in Lua parser |