lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Thu, Jun 28, 2018 at 2:37 PM, Egor Skriptunoff
<egor.skriptunoff@gmail.com> wrote:
>
>
> On Sat, May 21, 2016 at 8:18 AM, Egor Skriptunoff wrote:
>>
>>
>> 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()]
>>
>> The curious fact about this program is that it doesn't depend on anything
>> that can be changed.
>
>
>
> Here is an update of Lua version detector.
> Support for 5.0 and 5.4 was added.
>
> --[=[
> local version = 'Lua 5.0'
> --[[]=]
> local n = '8'; repeat n = n*n until n == n*n
> local t = {'Lua 5.1', nil,
>   [-1/0] = 'Lua 5.2',
>   [1/0]  = 'Lua 5.3',
>   [2]    = 'LuaJIT'}
> local version = t[2] or t[#'\z'] or t[n/'-0'] or 'Lua 5.4'
> --]]
>

Useful, but sadly this doesn't help distinguish between patch levels.

/s/ Adam