comparison loader.lua @ 14064:76ece4dd9782

loader: Move all path setup here from all executables So it is done in the same way for all the executables, with less code duplication.
author Kim Alvefur <zash@zash.se>
date Mon, 09 Feb 2026 01:57:40 +0100
parents ef586363d90f
children 50b8d732c905
comparison
equal deleted inserted replaced
14063:e73fdb09f080 14064:76ece4dd9782
1 -- Allow for both require"util.foo" and require"prosody.util.foo" for a 1 -- Allow for both require"util.foo" and require"prosody.util.foo" for a
2 -- transition period while we update all require calls. 2 -- transition period while we update all require calls.
3 3
4 if (...) == "prosody.loader" then 4 if (...) == "prosody.loader" then
5 local function is_relative(path)
6 local path_sep = package.config:sub(1,1);
7 return ((path_sep == "/" and path:sub(1,1) ~= "/")
8 or (path_sep == "\\" and (path:sub(1,1) ~= "/" and path:sub(2,3) ~= ":\\")))
9 end
10 local function filter_relative_paths(path)
11 if is_relative(path) then return ""; end
12 end
13 local function sanitise_paths(paths)
14 return (paths:gsub("[^;]+;?", filter_relative_paths):gsub(";;+", ";"));
15 end
16
5 -- For require"util.foo" also look in paths equivalent to "prosody.util.foo" 17 -- For require"util.foo" also look in paths equivalent to "prosody.util.foo"
6 package.path = package.path:gsub("([^;]*)(?[^;]*)", "%1prosody/%2;%1%2"); 18 package.path = sanitise_paths(CFG_SOURCEDIR.."/?.lua;"..package.path:gsub("([^;]*)(?[^;]*)", "%1prosody/%2;%1%2"));
7 package.cpath = package.cpath:gsub("([^;]*)(?[^;]*)", "%1prosody/%2;%1%2"); 19 package.cpath = sanitise_paths(CFG_SOURCEDIR.."/?.so;"..package.cpath:gsub("([^;]*)(?[^;]*)", "%1prosody/%2;%1%2"));
8 else 20 else
9 -- When requiring "prosody.x", also look for "x" 21 -- When requiring "prosody.x", also look for "x"
10 for i = #package.searchers, 1, -1 do 22 for i = #package.searchers, 1, -1 do
11 local search = package.searchers[i]; 23 local search = package.searchers[i];
12 table.insert(package.searchers, i, function(module_name) 24 table.insert(package.searchers, i, function(module_name)