From 9ca3222061fcc07a7ac5f685d80b49944b347a03 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Wed, 15 Feb 2023 17:08:36 +0100 Subject: [PATCH] fix(cache): lsmod now also supports lua libs. Fixes #544 --- lua/lazy/core/cache.lua | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lua/lazy/core/cache.lua b/lua/lazy/core/cache.lua index 3b3d824..12515ec 100644 --- a/lua/lazy/core/cache.lua +++ b/lua/lazy/core/cache.lua @@ -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