mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-08-25 19:16:44 +00:00
commit
f5fb82cd7d
@ -31,22 +31,37 @@ local function preload(package)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function from_file(package, env, dir)
|
local function from_file(package, env)
|
||||||
return function(name)
|
return function(name)
|
||||||
local fname = string.gsub(name, "%.", "/")
|
local sPath, sError = package.searchpath(name, package.path)
|
||||||
local sError = ""
|
if not sPath then
|
||||||
for pattern in string.gmatch(package.path, "[^;]+") do
|
return nil, sError
|
||||||
local sPath = string.gsub(pattern, "%?", fname)
|
|
||||||
if sPath:sub(1, 1) ~= "/" then
|
|
||||||
sPath = fs.combine(dir, sPath)
|
|
||||||
end
|
end
|
||||||
if fs.exists(sPath) and not fs.isDir(sPath) then
|
|
||||||
local fnFile, sError = loadfile(sPath, nil, env)
|
local fnFile, sError = loadfile(sPath, nil, env)
|
||||||
if fnFile then
|
if fnFile then
|
||||||
return fnFile, sPath
|
return fnFile, sPath
|
||||||
else
|
else
|
||||||
return nil, sError
|
return nil, sError
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function make_searchpath(dir)
|
||||||
|
return function(name, path, sep, rep)
|
||||||
|
expect(1, name, "string")
|
||||||
|
expect(2, path, "string")
|
||||||
|
sep = expect(3, sep, "string", "nil") or "."
|
||||||
|
rep = expect(4, rep, "string", "nil") or "/"
|
||||||
|
|
||||||
|
local fname = string.gsub(name, sep:gsub("%.", "%%%."), rep)
|
||||||
|
local sError = ""
|
||||||
|
for pattern in string.gmatch(path, "[^;]+") do
|
||||||
|
local sPath = string.gsub(pattern, "%?", fname)
|
||||||
|
if sPath:sub(1, 1) ~= "/" then
|
||||||
|
sPath = fs.combine(dir, sPath)
|
||||||
|
end
|
||||||
|
if fs.exists(sPath) and not fs.isDir(sPath) then
|
||||||
|
return sPath
|
||||||
else
|
else
|
||||||
if #sError > 0 then
|
if #sError > 0 then
|
||||||
sError = sError .. "\n "
|
sError = sError .. "\n "
|
||||||
@ -118,7 +133,8 @@ local function make_package(env, dir)
|
|||||||
end
|
end
|
||||||
package.config = "/\n;\n?\n!\n-"
|
package.config = "/\n;\n?\n!\n-"
|
||||||
package.preload = {}
|
package.preload = {}
|
||||||
package.loaders = { preload(package), from_file(package, env, dir) }
|
package.loaders = { preload(package), from_file(package, env) }
|
||||||
|
package.searchpath = make_searchpath(dir)
|
||||||
|
|
||||||
return make_require(package), package
|
return make_require(package), package
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user