mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
refactor(loader): simplify Loader.loader_lib
This commit is contained in:
@@ -205,14 +205,18 @@ function Loader.loader(modname)
|
||||
return ("\n\tcache_loader: module '%s' not found"):format(modname)
|
||||
end
|
||||
|
||||
local is_win = vim.fn.has('win32') == 1
|
||||
|
||||
--- The `package.loaders` loader for libs
|
||||
---@param modname string module name
|
||||
---@return string|function
|
||||
---@private
|
||||
function Loader.loader_lib(modname)
|
||||
local is_win = vim.fn.has('win32') == 1
|
||||
local ret = M.find(modname, { patterns = is_win and { '.dll' } or { '.so' } })[1]
|
||||
if ret then
|
||||
local ret = M.find(modname, { patterns = { is_win and '.dll' or '.so' } })[1]
|
||||
if not ret then
|
||||
return ("\n\tcache_loader_lib: module '%s' not found"):format(modname)
|
||||
end
|
||||
|
||||
-- Making function name in Lua 5.1 (see src/loadlib.c:mkfuncname) is
|
||||
-- a) strip prefix up to and including the first dash, if any
|
||||
-- b) replace all dots by underscores
|
||||
@@ -222,8 +226,6 @@ function Loader.loader_lib(modname)
|
||||
local funcname = dash and modname:sub(dash + 1) or modname
|
||||
local chunk, err = package.loadlib(ret.modpath, 'luaopen_' .. funcname:gsub('%.', '_'))
|
||||
return chunk or error(err)
|
||||
end
|
||||
return ("\n\tcache_loader_lib: module '%s' not found"):format(modname)
|
||||
end
|
||||
|
||||
--- `loadfile` using the cache
|
||||
|
Reference in New Issue
Block a user