Skip to content

Instantly share code, notes, and snippets.

@mystix
Forked from un-def/luaversion.lua
Created July 18, 2024 02:33
Show Gist options
  • Save mystix/6b60c22f8141cc0ab1035444794e5d22 to your computer and use it in GitHub Desktop.
Save mystix/6b60c22f8141cc0ab1035444794e5d22 to your computer and use it in GitHub Desktop.
A simple function to detect Lua version
local luaversion = function()
if ({false, [1] = true})[1] then -- luacheck: ignore 314
return 'LuaJIT'
elseif 1 / 0 == 1 / '-0' then
return 0 + '0' .. '' == '0' and 'Lua 5.4' or 'Lua 5.3'
end
local f = function() return function() end end
return f() == f() and 'Lua 5.2' or 'Lua 5.1'
end
return {
luaversion = luaversion,
}
#!/bin/sh
if ! command -V hererocks > /dev/null; then
echo 'hererocks not found'
exit 1
fi
echo "using $(hererocks --version)"
echo
tmp=$(mktemp -d)
trap 'rm -r "${tmp}"; trap - EXIT' EXIT INT QUIT TERM HUP
for lua in 'lua 5.1' 'lua 5.2' 'lua 5.3' 'lua 5.4' 'luajit 2.0' 'luajit 2.1'; do
echo "installing ${lua}"
lua_dir="${tmp}/$(echo "${lua}" | tr ' .' '_')"
if ! install_log=$(eval hererocks "--${lua}" "${lua_dir}" 2>&1); then
echo "failed to install ${lua}:"
echo "${install_log}"
exit 1
fi
lua_bin="${lua_dir}/bin/lua"
echo "installed $(${lua_bin} -v 2>&1)"
echo "_VERSION = $("${lua_bin}" -e 'print(_VERSION)')"
echo "luaversion() = $("${lua_bin}" -e 'print(require("luaversion").luaversion())')"
echo
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment