Skip to content

Instantly share code, notes, and snippets.

@TheGreatSageEqualToHeaven
Last active July 10, 2025 09:26
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 ("0" .. 0.010101010101010101010101010101010101010101010101) == "00.010101010101010102" then
return "Lua 5.5"
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