From 500aeba152d6da90331788885df99ea314081c6f Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Wed, 7 Dec 2022 20:15:43 -0300 Subject: path.path_to_module: accept custom extensions in package.(c)path (#1468) --- src/luarocks/core/path.lua | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/luarocks/core/path.lua b/src/luarocks/core/path.lua index bf6bdc2d..b354a41a 100644 --- a/src/luarocks/core/path.lua +++ b/src/luarocks/core/path.lua @@ -44,24 +44,29 @@ end function path.path_to_module(file) assert(type(file) == "string") - local name = file:match("(.*)%."..cfg.lua_extension.."$") - if name then - name = name:gsub("/", ".") - else - name = file:match("(.*)%."..cfg.lib_extension.."$") + local exts = {} + local paths = package.path .. ";" .. package.cpath + for entry in paths:gmatch("[^;]+") do + local ext = entry:match("%.([a-z]+)$") + if ext then + exts[ext] = true + end + end + + local name + for ext, _ in pairs(exts) do + name = file:match("(.*)%." .. ext .. "$") if name then - name = name:gsub("/", ".") - --[[ TODO disable static libs until we fix the conflict in the manifest, which will take extending the manifest format. - else - name = file:match("(.*)%."..cfg.static_lib_extension.."$") - if name then - name = name:gsub("/", ".") - end - ]] + name = name:gsub("[/\\]", ".") + break end end + if not name then name = file end + + -- remove any beginning and trailing slashes-converted-to-dots name = name:gsub("^%.+", ""):gsub("%.+$", "") + return name end -- cgit v1.2.3-55-g6feb