X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=core%2Fmoduleapi.lua;h=ed75669b60b64f6c90e5c19f9ee843328f20ec55;hb=b85f75e110d99b890fc22186cb2ad4d0c8f1d0a5;hp=30360f73547354afc245f2f2065ed35573f2ad02;hpb=5e9c7c0c3a5d90cb93517c5fcddcaddc0d55df84;p=prosody.git diff --git a/core/moduleapi.lua b/core/moduleapi.lua index 30360f73..ed75669b 100644 --- a/core/moduleapi.lua +++ b/core/moduleapi.lua @@ -270,6 +270,22 @@ function api:get_option_set(name, ...) return set.new(value); end +function api:get_option_inherited_set(name, ...) + local value = self:get_option_set(name, ...); + local global_value = self:context("*"):get_option_set(name, ...); + if not value then + return global_value; + elseif not global_value then + return value; + end + value:include(global_value); + return value; +end + +function api:context(host) + return setmetatable({host=host or "*"}, {__index=self,__newindex=self}); +end + function api:add_item(key, value) self.items = self.items or {}; self.items[key] = self.items[key] or {}; @@ -303,7 +319,13 @@ function api:handle_items(type, added_cb, removed_cb, existing) end function api:provides(name, item) - if not item then item = self.environment; end + -- if not item then item = setmetatable({}, { __index = function(t,k) return rawget(self.environment, k); end }); end + if not item then + item = {} + for k,v in pairs(self.environment) do + if k ~= "module" then item[k] = v; end + end + end if not item.name then local item_name = self.name; -- Strip a provider prefix to find the item name @@ -313,6 +335,7 @@ function api:provides(name, item) end item.name = item_name; end + item._provided_by = self.name; self:add_item(name.."-provider", item); end