aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2023-03-17 15:11:26 +0100
committerKim Alvefur <zash@zash.se>2023-03-17 15:11:26 +0100
commit93ddf6892ca32532ff4296e3ac01cd240eb1d56b (patch)
tree5239eaecb5a43d616389a56e59a520b4335f5ebf
parentd06cc5176ba05a20ea772814ef466616405bf1bd (diff)
downloadprosody-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"
-rw-r--r--loader.lua14
1 files changed, 14 insertions, 0 deletions
diff --git a/loader.lua b/loader.lua
index ddd25a82..9c2176a7 100644
--- a/loader.lua
+++ b/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;
+})