-
-
Save mystix/6b60c22f8141cc0ab1035444794e5d22 to your computer and use it in GitHub Desktop.
A simple function to detect Lua version
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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