moduleapi: module:provides called without an item makes a copy of the environment instead. Fixes warnings about non-existent globals
authorKim Alvefur <zash@zash.se>
Sat, 27 Apr 2013 19:14:22 +0200
changeset 5529 af58eea131b4
parent 5527 7e7f45f587a1
child 5530 d83482fc4a81
moduleapi: module:provides called without an item makes a copy of the environment instead. Fixes warnings about non-existent globals
core/moduleapi.lua
--- a/core/moduleapi.lua	Sat Apr 27 14:59:00 2013 +0100
+++ b/core/moduleapi.lua	Sat Apr 27 19:14:22 2013 +0200
@@ -319,7 +319,13 @@
 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