From ee8194313e61c9d0d7b8a0d52d22b026a06282bb Mon Sep 17 00:00:00 2001 From: Pierre Chapuis Date: Fri, 26 Dec 2025 11:22:19 +0100 Subject: improve header matching for Lua 5.5+ --- src/luarocks/deps.lua | 10 +++++----- src/luarocks/deps.tl | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua index 3eded47a..90c11bd5 100644 --- a/src/luarocks/deps.lua +++ b/src/luarocks/deps.lua @@ -705,19 +705,19 @@ function deps.scan_deps(results, mdeps, name, version, deps_mode) end local function lua_h_exists(d, luaver) - local major, minor = luaver:match("(%d+)%.(%d+)") - local luanum = ("%s%02d"):format(major, math.tointeger(minor)) + local major_s, minor_s = luaver:match("(%d+)%.(%d+)") + local major, minor = math.tointeger(major_s), math.tointeger(minor_s) local lua_h = dir.path(d, "lua.h") local fd = io.open(lua_h) if fd then local data = fd:read("*a") fd:close() - if major == "5" and minor == "5" then - if data:match("LUA_VERSION_MINOR_N%s5") and data:match("LUA_VERSION_MAJOR_N%s5") then + if vers.parse_version(("%d.%d"):format(major, minor)) >= vers.parse_version("5.5") then + if data:match("LUA_VERSION_MAJOR_N%s+" .. major) and data:match("LUA_VERSION_MINOR_N%s+" .. minor) then return d ~= nil end - elseif data:match("LUA_VERSION_NUM%s*" .. tostring(luanum)) then + elseif data:match("LUA_VERSION_NUM%s*" .. ("%d%02d"):format(major, minor)) then return d ~= nil end return nil, "Lua header lua.h found at " .. d .. " does not match Lua version " .. luaver .. ". You can use `luarocks config variables.LUA_INCDIR ` to set the correct location.", "dependency", 2 diff --git a/src/luarocks/deps.tl b/src/luarocks/deps.tl index 85980347..55006a95 100644 --- a/src/luarocks/deps.tl +++ b/src/luarocks/deps.tl @@ -705,19 +705,19 @@ function deps.scan_deps(results: {string: string}, mdeps: {string: {string: {Que end local function lua_h_exists(d: string, luaver: string): boolean, string, string, integer - local major, minor = luaver:match("(%d+)%.(%d+)") - local luanum = ("%s%02d"):format(major, math.tointeger(minor)) + local major_s, minor_s = luaver:match("(%d+)%.(%d+)") + local major, minor = math.tointeger(major_s), math.tointeger(minor_s) local lua_h = dir.path(d, "lua.h") local fd = io.open(lua_h) if fd then local data = fd:read("*a") fd:close() - if major == "5" and minor == "5" then - if data:match("LUA_VERSION_MINOR_N%s5") and data:match("LUA_VERSION_MAJOR_N%s5") then + if vers.parse_version(("%d.%d"):format(major, minor)) >= vers.parse_version("5.5") then + if data:match("LUA_VERSION_MAJOR_N%s+" .. major) and data:match("LUA_VERSION_MINOR_N%s+" .. minor) then return d ~= nil end - elseif data:match("LUA_VERSION_NUM%s*" .. tostring(luanum)) then + elseif data:match("LUA_VERSION_NUM%s*" .. ("%d%02d"):format(major, minor)) then return d ~= nil end return nil, "Lua header lua.h found at " .. d .. " does not match Lua version " .. luaver .. ". You can use `luarocks config variables.LUA_INCDIR ` to set the correct location.", "dependency", 2 -- cgit v1.2.3-55-g6feb