Mercurial > prosody-hg
comparison loader.lua @ 12949:2f61ebcf37c0
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"
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Fri, 17 Mar 2023 15:11:26 +0100 |
| parents | 29983f09c913 |
| children | ef586363d90f |
comparison
equal
deleted
inserted
replaced
| 12948:29983f09c913 | 12949:2f61ebcf37c0 |
|---|---|
| 17 return search(lib); | 17 return search(lib); |
| 18 end | 18 end |
| 19 end) | 19 end) |
| 20 end | 20 end |
| 21 end | 21 end |
| 22 | |
| 23 -- Look for already loaded module with or without prefix | |
| 24 setmetatable(package.loaded, { | |
| 25 __index = function(loaded, module_name) | |
| 26 local suffix = module_name:match("^prosody%.(.*)$"); | |
| 27 if suffix then | |
| 28 return rawget(loaded, suffix); | |
| 29 end | |
| 30 local prefixed = rawget(loaded, "prosody." .. module_name); | |
| 31 if prefixed ~= nil then | |
| 32 return prefixed; | |
| 33 end | |
| 34 end; | |
| 35 }) |
