7 -- |
7 -- |
8 |
8 |
9 |
9 |
10 |
10 |
11 local _G = _G; |
11 local _G = _G; |
12 local setmetatable, loadfile, pcall, rawget, rawset, io = |
12 local setmetatable, loadfile, pcall, rawget, rawset, io, error = |
13 setmetatable, loadfile, pcall, rawget, rawset, io; |
13 setmetatable, loadfile, pcall, rawget, rawset, io, error; |
14 |
14 |
15 module "configmanager" |
15 module "configmanager" |
16 |
16 |
17 local parsers = {}; |
17 local parsers = {}; |
18 |
18 |
95 local setfenv, rawget, tostring = _G.setfenv, _G.rawget, _G.tostring; |
95 local setfenv, rawget, tostring = _G.setfenv, _G.rawget, _G.tostring; |
96 parsers.lua = {}; |
96 parsers.lua = {}; |
97 function parsers.lua.load(data) |
97 function parsers.lua.load(data) |
98 local env; |
98 local env; |
99 -- The ' = true' are needed so as not to set off __newindex when we assign the functions below |
99 -- The ' = true' are needed so as not to set off __newindex when we assign the functions below |
100 env = setmetatable({ Host = true; host = true; Component = true, component = true }, { __index = function (t, k) |
100 env = setmetatable({ Host = true; host = true; Component = true, component = true, |
|
101 Include = true, include = true }, { __index = function (t, k) |
101 return rawget(_G, k) or |
102 return rawget(_G, k) or |
102 function (settings_table) |
103 function (settings_table) |
103 config[__currenthost or "*"][k] = settings_table; |
104 config[__currenthost or "*"][k] = settings_table; |
104 end; |
105 end; |
105 end, |
106 end, |
122 rawset(env, "__currenthost", name); |
123 rawset(env, "__currenthost", name); |
123 end |
124 end |
124 end |
125 end |
125 env.component = env.Component; |
126 env.component = env.Component; |
126 |
127 |
|
128 function env.Include(file) |
|
129 local f, err = io.open(file); |
|
130 if f then |
|
131 local data = f:read("*a"); |
|
132 local ok, err = parsers.lua.load(data); |
|
133 if not ok then error(err:gsub("%[string.-%]", file), 0); end |
|
134 end |
|
135 if not f then error("Error loading included "..file..": "..err, 0); end |
|
136 return f, err; |
|
137 end |
|
138 env.include = env.Include; |
|
139 |
127 local chunk, err = loadstring(data); |
140 local chunk, err = loadstring(data); |
128 |
141 |
129 if not chunk then |
142 if not chunk then |
130 return nil, err; |
143 return nil, err; |
131 end |
144 end |