diff options
author | Kim Alvefur <zash@zash.se> | 2023-03-17 15:11:26 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2023-03-17 15:11:26 +0100 |
commit | 93ddf6892ca32532ff4296e3ac01cd240eb1d56b (patch) | |
tree | 5239eaecb5a43d616389a56e59a520b4335f5ebf /loader.lua | |
parent | d06cc5176ba05a20ea772814ef466616405bf1bd (diff) | |
download | prosody-93ddf6892ca32532ff4296e3ac01cd240eb1d56b.tar.gz prosody-93ddf6892ca32532ff4296e3ac01cd240eb1d56b.zip |
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"
Diffstat (limited to 'loader.lua')
-rw-r--r-- | loader.lua | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -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; +}) |