mirror of
https://github.com/bjc/prosody.git
synced 2025-03-31 11:47:40 +03:00
prosody.loader: Ensure already loaded modules are found in old and new namespaces
Prevents modules being initialized twice, ensuring that require"prosody.util.foo" == require"util.foo"
This commit is contained in:
parent
d06cc5176b
commit
93ddf6892c
1 changed files with 14 additions and 0 deletions
14
loader.lua
14
loader.lua
|
@ -19,3 +19,17 @@ else
|
|||
end)
|
||||
end
|
||||
end
|
||||
|
||||
-- Look for already loaded module with or without prefix
|
||||
setmetatable(package.loaded, {
|
||||
__index = function(loaded, module_name)
|
||||
local suffix = module_name:match("^prosody%.(.*)$");
|
||||
if suffix then
|
||||
return rawget(loaded, suffix);
|
||||
end
|
||||
local prefixed = rawget(loaded, "prosody." .. module_name);
|
||||
if prefixed ~= nil then
|
||||
return prefixed;
|
||||
end
|
||||
end;
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue