aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/loader.lua
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2024-10-31 14:25:00 +0000
committerLewis Russell <lewis6991@gmail.com>2024-10-31 15:20:27 +0000
commitab2f2461b5ec2fd3a9c0924cd7dcfaa6028b8d21 (patch)
tree228ab770e9dc03b5669648251a1337b6a1b4e1ab /runtime/lua/vim/loader.lua
parent53536be62a9efe8e641214a3950b904e108bfe28 (diff)
downloadrneovim-ab2f2461b5ec2fd3a9c0924cd7dcfaa6028b8d21.tar.gz
rneovim-ab2f2461b5ec2fd3a9c0924cd7dcfaa6028b8d21.tar.bz2
rneovim-ab2f2461b5ec2fd3a9c0924cd7dcfaa6028b8d21.zip
refactor(loader): simplify Loader.loader_lib
Diffstat (limited to 'runtime/lua/vim/loader.lua')
-rw-r--r--runtime/lua/vim/loader.lua28
1 files changed, 15 insertions, 13 deletions
diff --git a/runtime/lua/vim/loader.lua b/runtime/lua/vim/loader.lua
index 904036806c..21662668e3 100644
--- a/runtime/lua/vim/loader.lua
+++ b/runtime/lua/vim/loader.lua
@@ -205,25 +205,27 @@ 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
- -- 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
- -- c) prepend "luaopen_"
- -- So "foo-bar.baz" should result in "luaopen_bar_baz"
- local dash = modname:find('-', 1, true)
- 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)
+ 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
- return ("\n\tcache_loader_lib: module '%s' not found"):format(modname)
+
+ -- 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
+ -- c) prepend "luaopen_"
+ -- So "foo-bar.baz" should result in "luaopen_bar_baz"
+ local dash = modname:find('-', 1, true)
+ 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
--- `loadfile` using the cache