fix(cache): lsmod now also supports lua libs. Fixes #544

This commit is contained in:
Folke Lemaitre 2023-02-15 17:08:36 +01:00
parent 78264fb935
commit 9ca3222061
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
1 changed files with 10 additions and 7 deletions

View File

@ -129,13 +129,13 @@ end
function Cache.loader(modname)
local start = uv.hrtime()
local modpath, hash = Cache.find(modname)
---@type function?, string?
local chunk, err
if modpath then
chunk, err = M.load(modpath, { hash = hash })
local chunk, err = M.load(modpath, { hash = hash })
M.track("loader", start)
return chunk or error(err)
end
M.track("loader", start)
return chunk or err or "module " .. modname .. " not found"
return "\nlazy_loader: module " .. modname .. " not found"
end
---@param modname string
@ -154,10 +154,10 @@ function Cache.loader_lib(modname)
local funcname = dash and modname:sub(dash + 1) or modname
local chunk, err = package.loadlib(modpath, "luaopen_" .. funcname:gsub("%.", "_"))
M.track("loader_lib", start)
return chunk or err
return chunk or error(err)
end
M.track("loader_lib", start)
return "module " .. modname .. " not found"
return "\nlazy_loader_lib: module " .. modname .. " not found"
end
---@param filename? string
@ -337,8 +337,11 @@ function M.lsmod(path)
t = t or uv.fs_stat(path .. "/" .. name).type
---@type string
local topname
if name:sub(-4) == ".lua" then
local ext = name:sub(-4)
if ext == ".lua" or ext == ".dll" then
topname = name:sub(1, -5)
elseif name:sub(-3) == ".so" then
topname = name:sub(1, -4)
elseif t == "link" or t == "directory" then
topname = name
end