Skip to content

Commit

Permalink
fix(cache): lsmod now also supports lua libs. Fixes #544
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Feb 15, 2023
1 parent 78264fb commit 9ca3222
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lua/lazy/core/cache.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9ca3222

Please sign in to comment.