Software /
code /
prosody
Annotate
core/configmanager.lua @ 790:f42ad7385640
Fixed: User resources not disconnected correctly on account delete
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Thu, 12 Feb 2009 18:09:17 +0500 |
parent | 760:90ce865eebd8 |
child | 793:55add3b87c01 |
rev | line source |
---|---|
759 | 1 -- Prosody IM v0.3 |
760
90ce865eebd8
Update copyright notices for 2009
Matthew Wild <mwild1@gmail.com>
parents:
759
diff
changeset
|
2 -- Copyright (C) 2008-2009 Matthew Wild |
90ce865eebd8
Update copyright notices for 2009
Matthew Wild <mwild1@gmail.com>
parents:
759
diff
changeset
|
3 -- Copyright (C) 2008-2009 Waqas Hussain |
519
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
466
diff
changeset
|
4 -- |
758 | 5 -- This project is MIT/X11 licensed. Please see the |
6 -- COPYING file in the source package for more information. | |
519
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
466
diff
changeset
|
7 -- |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
466
diff
changeset
|
8 |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
466
diff
changeset
|
9 |
371
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 local _G = _G; |
376
6d87944df37c
New configmanager. Old-style config files still work, but will print a warning
Matthew Wild <mwild1@gmail.com>
parents:
371
diff
changeset
|
12 local setmetatable, loadfile, pcall, rawget, rawset, io = |
6d87944df37c
New configmanager. Old-style config files still work, but will print a warning
Matthew Wild <mwild1@gmail.com>
parents:
371
diff
changeset
|
13 setmetatable, loadfile, pcall, rawget, rawset, io; |
466
0ecfd89c2cc0
Fix for configmanager when config file can't be found
Matthew Wild <mwild1@gmail.com>
parents:
376
diff
changeset
|
14 |
371
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 module "configmanager" |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 local parsers = {}; |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 local config = { ["*"] = { core = {} } }; |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 local global_config = config["*"]; |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 -- When host not found, use global |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 setmetatable(config, { __index = function () return global_config; end}); |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 local host_mt = { __index = global_config }; |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 -- When key not found in section, check key in global's section |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 function section_mt(section_name) |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 return { __index = function (t, k) |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 local section = rawget(global_config, section_name); |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 if not section then return nil; end |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 return section[k]; |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 end }; |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 end |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 |
376
6d87944df37c
New configmanager. Old-style config files still work, but will print a warning
Matthew Wild <mwild1@gmail.com>
parents:
371
diff
changeset
|
36 function getconfig() |
6d87944df37c
New configmanager. Old-style config files still work, but will print a warning
Matthew Wild <mwild1@gmail.com>
parents:
371
diff
changeset
|
37 return config; |
6d87944df37c
New configmanager. Old-style config files still work, but will print a warning
Matthew Wild <mwild1@gmail.com>
parents:
371
diff
changeset
|
38 end |
6d87944df37c
New configmanager. Old-style config files still work, but will print a warning
Matthew Wild <mwild1@gmail.com>
parents:
371
diff
changeset
|
39 |
371
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 function get(host, section, key) |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 local sec = config[host][section]; |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 if sec then |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 return sec[key]; |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 end |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 return nil; |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 end |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 function set(host, section, key, value) |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 if host and section and key then |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 local hostconfig = rawget(config, host); |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 if not hostconfig then |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 hostconfig = rawset(config, host, setmetatable({}, host_mt))[host]; |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 end |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 if not rawget(hostconfig, section) then |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 hostconfig[section] = setmetatable({}, section_mt(section)); |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 end |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 hostconfig[section][key] = value; |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
58 return true; |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
59 end |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
60 return false; |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
61 end |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
62 |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
63 function load(filename, format) |
376
6d87944df37c
New configmanager. Old-style config files still work, but will print a warning
Matthew Wild <mwild1@gmail.com>
parents:
371
diff
changeset
|
64 format = format or filename:match("%w+$"); |
466
0ecfd89c2cc0
Fix for configmanager when config file can't be found
Matthew Wild <mwild1@gmail.com>
parents:
376
diff
changeset
|
65 |
371
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
66 if parsers[format] and parsers[format].load then |
466
0ecfd89c2cc0
Fix for configmanager when config file can't be found
Matthew Wild <mwild1@gmail.com>
parents:
376
diff
changeset
|
67 local f, err = io.open(filename); |
371
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
68 if f then |
376
6d87944df37c
New configmanager. Old-style config files still work, but will print a warning
Matthew Wild <mwild1@gmail.com>
parents:
371
diff
changeset
|
69 local ok, err = parsers[format].load(f:read("*a")); |
371
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
70 f:close(); |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
71 return ok, err; |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
72 end |
466
0ecfd89c2cc0
Fix for configmanager when config file can't be found
Matthew Wild <mwild1@gmail.com>
parents:
376
diff
changeset
|
73 return f, err; |
371
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
74 end |
466
0ecfd89c2cc0
Fix for configmanager when config file can't be found
Matthew Wild <mwild1@gmail.com>
parents:
376
diff
changeset
|
75 |
376
6d87944df37c
New configmanager. Old-style config files still work, but will print a warning
Matthew Wild <mwild1@gmail.com>
parents:
371
diff
changeset
|
76 if not format then |
6d87944df37c
New configmanager. Old-style config files still work, but will print a warning
Matthew Wild <mwild1@gmail.com>
parents:
371
diff
changeset
|
77 return nil, "no parser specified"; |
6d87944df37c
New configmanager. Old-style config files still work, but will print a warning
Matthew Wild <mwild1@gmail.com>
parents:
371
diff
changeset
|
78 else |
466
0ecfd89c2cc0
Fix for configmanager when config file can't be found
Matthew Wild <mwild1@gmail.com>
parents:
376
diff
changeset
|
79 return nil, "no parser for "..(format); |
376
6d87944df37c
New configmanager. Old-style config files still work, but will print a warning
Matthew Wild <mwild1@gmail.com>
parents:
371
diff
changeset
|
80 end |
371
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
81 end |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
82 |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
83 function save(filename, format) |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
84 end |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
85 |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
86 function addparser(format, parser) |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
87 if format and parser then |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
88 parsers[format] = parser; |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
89 end |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
90 end |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
91 |
376
6d87944df37c
New configmanager. Old-style config files still work, but will print a warning
Matthew Wild <mwild1@gmail.com>
parents:
371
diff
changeset
|
92 -- Built-in Lua parser |
371
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
93 do |
376
6d87944df37c
New configmanager. Old-style config files still work, but will print a warning
Matthew Wild <mwild1@gmail.com>
parents:
371
diff
changeset
|
94 local loadstring, pcall, setmetatable = _G.loadstring, _G.pcall, _G.setmetatable; |
6d87944df37c
New configmanager. Old-style config files still work, but will print a warning
Matthew Wild <mwild1@gmail.com>
parents:
371
diff
changeset
|
95 local setfenv, rawget, tostring = _G.setfenv, _G.rawget, _G.tostring; |
371
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
96 parsers.lua = {}; |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
97 function parsers.lua.load(data) |
376
6d87944df37c
New configmanager. Old-style config files still work, but will print a warning
Matthew Wild <mwild1@gmail.com>
parents:
371
diff
changeset
|
98 local env; |
750
fbfcf8c1c830
configmanager: Add support for defining components
Matthew Wild <mwild1@gmail.com>
parents:
615
diff
changeset
|
99 -- The ' = true' are needed so as not to set off __newindex when we assign the functions below |
fbfcf8c1c830
configmanager: Add support for defining components
Matthew Wild <mwild1@gmail.com>
parents:
615
diff
changeset
|
100 env = setmetatable({ Host = true; host = true; Component = true, component = true }, { __index = function (t, k) |
376
6d87944df37c
New configmanager. Old-style config files still work, but will print a warning
Matthew Wild <mwild1@gmail.com>
parents:
371
diff
changeset
|
101 return rawget(_G, k) or |
6d87944df37c
New configmanager. Old-style config files still work, but will print a warning
Matthew Wild <mwild1@gmail.com>
parents:
371
diff
changeset
|
102 function (settings_table) |
371
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
103 config[__currenthost or "*"][k] = settings_table; |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
104 end; |
376
6d87944df37c
New configmanager. Old-style config files still work, but will print a warning
Matthew Wild <mwild1@gmail.com>
parents:
371
diff
changeset
|
105 end, |
6d87944df37c
New configmanager. Old-style config files still work, but will print a warning
Matthew Wild <mwild1@gmail.com>
parents:
371
diff
changeset
|
106 __newindex = function (t, k, v) |
6d87944df37c
New configmanager. Old-style config files still work, but will print a warning
Matthew Wild <mwild1@gmail.com>
parents:
371
diff
changeset
|
107 set(env.__currenthost or "*", "core", k, v); |
371
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
108 end}); |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
109 |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
110 function env.Host(name) |
376
6d87944df37c
New configmanager. Old-style config files still work, but will print a warning
Matthew Wild <mwild1@gmail.com>
parents:
371
diff
changeset
|
111 rawset(env, "__currenthost", name); |
750
fbfcf8c1c830
configmanager: Add support for defining components
Matthew Wild <mwild1@gmail.com>
parents:
615
diff
changeset
|
112 -- Needs at least one setting to logically exist :) |
376
6d87944df37c
New configmanager. Old-style config files still work, but will print a warning
Matthew Wild <mwild1@gmail.com>
parents:
371
diff
changeset
|
113 set(name or "*", "core", "defined", true); |
371
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
114 end |
376
6d87944df37c
New configmanager. Old-style config files still work, but will print a warning
Matthew Wild <mwild1@gmail.com>
parents:
371
diff
changeset
|
115 env.host = env.Host; |
371
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
116 |
750
fbfcf8c1c830
configmanager: Add support for defining components
Matthew Wild <mwild1@gmail.com>
parents:
615
diff
changeset
|
117 function env.Component(name) |
fbfcf8c1c830
configmanager: Add support for defining components
Matthew Wild <mwild1@gmail.com>
parents:
615
diff
changeset
|
118 return function (module) |
fbfcf8c1c830
configmanager: Add support for defining components
Matthew Wild <mwild1@gmail.com>
parents:
615
diff
changeset
|
119 set(name, "core", "component_module", module); |
fbfcf8c1c830
configmanager: Add support for defining components
Matthew Wild <mwild1@gmail.com>
parents:
615
diff
changeset
|
120 -- Don't load the global modules by default |
fbfcf8c1c830
configmanager: Add support for defining components
Matthew Wild <mwild1@gmail.com>
parents:
615
diff
changeset
|
121 set(name, "core", "modules_enable", false); |
fbfcf8c1c830
configmanager: Add support for defining components
Matthew Wild <mwild1@gmail.com>
parents:
615
diff
changeset
|
122 rawset(env, "__currenthost", name); |
fbfcf8c1c830
configmanager: Add support for defining components
Matthew Wild <mwild1@gmail.com>
parents:
615
diff
changeset
|
123 end |
fbfcf8c1c830
configmanager: Add support for defining components
Matthew Wild <mwild1@gmail.com>
parents:
615
diff
changeset
|
124 end |
fbfcf8c1c830
configmanager: Add support for defining components
Matthew Wild <mwild1@gmail.com>
parents:
615
diff
changeset
|
125 env.component = env.Component; |
fbfcf8c1c830
configmanager: Add support for defining components
Matthew Wild <mwild1@gmail.com>
parents:
615
diff
changeset
|
126 |
371
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
127 local chunk, err = loadstring(data); |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
128 |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
129 if not chunk then |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
130 return nil, err; |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
131 end |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
132 |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
133 setfenv(chunk, env); |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
134 |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
135 local ok, err = pcall(chunk); |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
136 |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
137 if not ok then |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
138 return nil, err; |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
139 end |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
140 |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
141 return true; |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
142 end |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
143 |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
144 end |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
145 |
466
0ecfd89c2cc0
Fix for configmanager when config file can't be found
Matthew Wild <mwild1@gmail.com>
parents:
376
diff
changeset
|
146 return _M; |