[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: A tricky way to determine Lua version
- From: Sean Conner <sean@...>
- Date: Sat, 21 May 2016 02:42:11 -0400
It was thus said that the Great Egor Skriptunoff once stated:
> Hi!
>
> I want to share simple program that determines Lua version.
>
> local f, t = function()return function()end end, {nil,
> [false] = 'Lua 5.1',
> [true] = 'Lua 5.2',
> [1/'-0'] = 'Lua 5.3',
> [1] = 'LuaJIT' }
> local version = t[1] or t[1/0] or t[f()==f()]
Nice.
I couldn't resist writing my own version.
local version = ({Q="Lua 5.1",R="Lua 5.2",S="Lua 5.3"})[
("").dump(function() end):sub(5,5)]
Mine relies upon strings still having a metatable.
-spc