From 82faa21dd3bda1ca9853f385d1e37159fa05afc2 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 27 Apr 2013 14:57:24 +0100 Subject: moduleapi: Add module:context(host) to produce a fake API context for a given host (or global). module:context("*"):get_option("foo") to get global options. --- core/moduleapi.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/moduleapi.lua b/core/moduleapi.lua index 30360f73..da44db5f 100644 --- a/core/moduleapi.lua +++ b/core/moduleapi.lua @@ -270,6 +270,10 @@ function api:get_option_set(name, ...) return set.new(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 {}; -- cgit v1.2.3 From bcc1074dd55582c565d0fe6349f3eb686d2f6fab Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 27 Apr 2013 14:59:00 +0100 Subject: moduleapi: Add module:get_option_inherited_set() to return a set that inherits items from a globally set set, if set --- core/moduleapi.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/moduleapi.lua b/core/moduleapi.lua index da44db5f..9baf4fba 100644 --- a/core/moduleapi.lua +++ b/core/moduleapi.lua @@ -270,6 +270,18 @@ 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 -- cgit v1.2.3