mirror of
https://github.com/appgurueu/modlib.git
synced 2024-08-19 21:04:13 +02:00
Patch globals leaking into modlib modules
This commit is contained in:
parent
b433b30dbe
commit
8dc3054dd0
15
init.lua
15
init.lua
@ -101,14 +101,21 @@ modlib = setmetatable({
|
||||
}, {
|
||||
__index = function(self, module_name)
|
||||
local files = modules[module_name]
|
||||
local module
|
||||
local environment
|
||||
if type(files) == "string" then
|
||||
module = load_module(files)
|
||||
environment = load_module(files)
|
||||
elseif files then
|
||||
module = loadfile_exports(get_resource(self.modname, module_name, files[1] .. ".lua"))
|
||||
environment = loadfile_exports(get_resource(self.modname, module_name, files[1] .. ".lua"))
|
||||
for index = 2, #files do
|
||||
self.mod.include_env(get_resource(self.modname, module_name, files[index] .. ".lua"), module)
|
||||
self.mod.include_env(get_resource(self.modname, module_name, files[index] .. ".lua"), environment)
|
||||
end
|
||||
else
|
||||
return
|
||||
end
|
||||
local module = {}
|
||||
for key, value in pairs(environment) do
|
||||
-- Shallow copy. Doesn't use `modlib.table.shallowcopy` as that is part of a module, too.
|
||||
module[key] = value
|
||||
end
|
||||
self[module_name] = module
|
||||
return module
|
||||
|
3
test.lua
3
test.lua
@ -1,3 +1,6 @@
|
||||
-- ensure modlib API isn't leaking into global environment
|
||||
assert(modlib.bluon.assert ~= assert)
|
||||
|
||||
local random, huge = math.random, math.huge
|
||||
local parent_env = getfenv(1)
|
||||
setfenv(1, setmetatable({}, {
|
||||
|
Loading…
Reference in New Issue
Block a user