修复 大小写文件名导致重复载入

This commit is contained in:
baidwwy 2021-05-02 11:07:30 +08:00
parent 9e47dffa27
commit d5916c5462
1 changed files with 22 additions and 9 deletions

View File

@ -1,7 +1,7 @@
--[[
@Author : baidwwy
@Date : 2020-09-22 19:49:01
@LastEditTime : 2021-04-11 04:28:34
@LastEditTime : 2021-05-02 11:02:57
--]]
require("ggelua")
io.stdout:setvbuf('no',0)
@ -37,7 +37,7 @@ package.cpath = nil
setmetatable(package, {
__newindex = function (t,k,v)
if v and k=='path' then
lpath = v:lower():gsub('\\','/')
lpath = v:upper():gsub('\\','/')
lpath_ = (lpath)
elseif k=='cpath' then
cpath = v
@ -71,7 +71,7 @@ local function 处理路径(path)
-- end
-- path = table.concat(t, "/")
path = path:lower()--小
path = path:upper()--大
path = path:gsub('%.','/')
path = path:gsub('\\','/')
return path
@ -160,17 +160,30 @@ local function 搜索路径(path)
end
end
local loaded = setmetatable({}, {__mode="v"})
table.insert(package.searchers, 1, function (path)
path = (path)
path = (path)
if path then
local r,err = load((path),path)
return r or error(err,2)
local npath = (path)
if loaded[npath]~=nil then
return function ()
return loaded[npath]
end
end
local fpath = (npath)
if fpath then
return function ()
local r,err = load((fpath),fpath)
if err then
return error(err,2)
end
local r = r()
loaded[npath] = r==nil and true or r
return loaded[npath]
end
end
end)
function gge.require(path,env,...)
path = path:gsub('\\','/'):lower()
path = path:gsub('\\','/'):upper()
local data = (path)
if data then
return assert(load(data,path,"bt",env))(...)