Skip to content

Instantly share code, notes, and snippets.

@TheGreatSageEqualToHeaven
Created March 28, 2024 01:35
Show Gist options
  • Save TheGreatSageEqualToHeaven/4c57fe3e5f71c0b361282d77c787095f to your computer and use it in GitHub Desktop.
Save TheGreatSageEqualToHeaven/4c57fe3e5f71c0b361282d77c787095f to your computer and use it in GitHub Desktop.
Runtime Lua version detection without _VERSION
local function luaVersion()
local f = function()
return function() end
end
if 0xffffffffffffffffffffffffffffffffffffffffffffff == 2 ^ 64 then
return "Luau"
end
if ({nil,[1] = true})[1] then
return "LuaJIT"
end
if 1/0 == 1/"-0" then
return ("1" + "2").."" == "3.0" and "Lua 5.3" or "Lua 5.4"
end
return f() == f() and "Lua 5.2" or "Lua 5.1"
end
print(luaVersion())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment