From 7ad8f743bb9fd9da6898263c3886f23dee194915 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 27 Apr 2013 19:14:22 +0200 Subject: moduleapi: module:provides called without an item makes a copy of the environment instead. Fixes warnings about non-existent globals --- core/moduleapi.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'core') diff --git a/core/moduleapi.lua b/core/moduleapi.lua index 9baf4fba..764ed52a 100644 --- a/core/moduleapi.lua +++ b/core/moduleapi.lua @@ -319,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 -- cgit v1.2.3 From d9bff06d21d62879c54ee40dbd654b4dbc89735f Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 27 Apr 2013 19:44:37 +0200 Subject: moduleapi: in module:provides(), add the name of the module in item._provided_by --- core/moduleapi.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'core') diff --git a/core/moduleapi.lua b/core/moduleapi.lua index 764ed52a..ed75669b 100644 --- a/core/moduleapi.lua +++ b/core/moduleapi.lua @@ -335,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 -- cgit v1.2.3