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.
authorMatthew Wild <mwild1@gmail.com>
Sat, 27 Apr 2013 14:57:24 +0100
changeset 5526 d54011a23b20
parent 5524 e9090966c803
child 5527 7e7f45f587a1
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
--- a/core/moduleapi.lua	Sat Apr 27 13:11:03 2013 +0100
+++ b/core/moduleapi.lua	Sat Apr 27 14:57:24 2013 +0100
@@ -270,6 +270,10 @@
 	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 {};