теперь она заменяет (вроде) все пути вроде ./?.lua ./?.luac на относительные к скрипту
do
local unpack = unpack or table.unpack;
local p = {}
local it = 1
while it < #package.path do
local pos = package.path:find(";", it)
if not pos then
table.insert(p, package.path:sub(it))
break
end
table.insert(p, package.path:sub(it, pos - 1))
it = pos + 1
end
local win = package.config:sub(1, 1) == "\\";
local sl, ls = unpack(win and {"\\", "/"} or {"/", "\\"});
local norm = function(path, parent, isdir)
local sp = path:gsub(ls, sl)
local is_abs = sp:sub(1, 1) == sl or (win and sp:find(":"));
local last = ({sp:find(".*" .. sl)})[2];
if parent then
sp = (last or is_abs) and sp:sub(1, last) or "";
end
if not is_abs and sp:sub(1, 2) ~= ("." .. sl) then
sp = "." .. sl .. sp;
end
if (parent or isdir) and sp:sub(-1, -1) ~= sl then
sp = sp .. sl;
end
return sp
end
local path = norm(arg[0], true);
local lookup = {
[("./??.[a-zA-Z0-9]+" ):gsub(ls, sl)] = 3,
[("./??/init.[a-zA-Z0-9]+"):gsub(ls, sl)] = 3
};
for k, v in pairs(p) do
local n = norm(v)
for lk, lv in pairs(lookup) do
local b, e = n:find(lk)
if b == 1 and e == #n then
p[k] = path .. n:sub(lv)
break
end
end
end
end