Comparison

core/moduleapi.lua @ 5529:af58eea131b4

moduleapi: module:provides called without an item makes a copy of the environment instead. Fixes warnings about non-existent globals
author Kim Alvefur <zash@zash.se>
date Sat, 27 Apr 2013 19:14:22 +0200
parent 5527:7e7f45f587a1
child 5530:d83482fc4a81
comparison
equal deleted inserted replaced
5527:7e7f45f587a1 5529:af58eea131b4
317 end 317 end
318 end 318 end
319 end 319 end
320 320
321 function api:provides(name, item) 321 function api:provides(name, item)
322 if not item then item = self.environment; end 322 -- if not item then item = setmetatable({}, { __index = function(t,k) return rawget(self.environment, k); end }); end
323 if not item then
324 item = {}
325 for k,v in pairs(self.environment) do
326 if k ~= "module" then item[k] = v; end
327 end
328 end
323 if not item.name then 329 if not item.name then
324 local item_name = self.name; 330 local item_name = self.name;
325 -- Strip a provider prefix to find the item name 331 -- Strip a provider prefix to find the item name
326 -- (e.g. "auth_foo" -> "foo" for an auth provider) 332 -- (e.g. "auth_foo" -> "foo" for an auth provider)
327 if item_name:find(name.."_", 1, true) == 1 then 333 if item_name:find(name.."_", 1, true) == 1 then