Software /
code /
prosody
Comparison
core/configmanager.lua @ 750:fbfcf8c1c830
configmanager: Add support for defining components
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 29 Jan 2009 02:13:30 +0000 |
parent | 615:4ae3e81513f3 |
child | 758:b1885732e979 |
comparison
equal
deleted
inserted
replaced
749:1359492f45d7 | 750:fbfcf8c1c830 |
---|---|
105 local loadstring, pcall, setmetatable = _G.loadstring, _G.pcall, _G.setmetatable; | 105 local loadstring, pcall, setmetatable = _G.loadstring, _G.pcall, _G.setmetatable; |
106 local setfenv, rawget, tostring = _G.setfenv, _G.rawget, _G.tostring; | 106 local setfenv, rawget, tostring = _G.setfenv, _G.rawget, _G.tostring; |
107 parsers.lua = {}; | 107 parsers.lua = {}; |
108 function parsers.lua.load(data) | 108 function parsers.lua.load(data) |
109 local env; | 109 local env; |
110 env = setmetatable({ Host = true; host = true; }, { __index = function (t, k) | 110 -- The ' = true' are needed so as not to set off __newindex when we assign the functions below |
111 env = setmetatable({ Host = true; host = true; Component = true, component = true }, { __index = function (t, k) | |
111 return rawget(_G, k) or | 112 return rawget(_G, k) or |
112 function (settings_table) | 113 function (settings_table) |
113 config[__currenthost or "*"][k] = settings_table; | 114 config[__currenthost or "*"][k] = settings_table; |
114 end; | 115 end; |
115 end, | 116 end, |
117 set(env.__currenthost or "*", "core", k, v); | 118 set(env.__currenthost or "*", "core", k, v); |
118 end}); | 119 end}); |
119 | 120 |
120 function env.Host(name) | 121 function env.Host(name) |
121 rawset(env, "__currenthost", name); | 122 rawset(env, "__currenthost", name); |
123 -- Needs at least one setting to logically exist :) | |
122 set(name or "*", "core", "defined", true); | 124 set(name or "*", "core", "defined", true); |
123 end | 125 end |
124 env.host = env.Host; | 126 env.host = env.Host; |
127 | |
128 function env.Component(name) | |
129 return function (module) | |
130 set(name, "core", "component_module", module); | |
131 -- Don't load the global modules by default | |
132 set(name, "core", "modules_enable", false); | |
133 rawset(env, "__currenthost", name); | |
134 end | |
135 end | |
136 env.component = env.Component; | |
125 | 137 |
126 local chunk, err = loadstring(data); | 138 local chunk, err = loadstring(data); |
127 | 139 |
128 if not chunk then | 140 if not chunk then |
129 return nil, err; | 141 return nil, err; |