lua-users home
lua-l archive

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


>>>>> "Egor" == Egor Skriptunoff <egor.skriptunoff@gmail.com> writes:

 Egor> local f, t = function()return function()end end, {nil,
 Egor>    [false] = {[-1/0] = 'Lua 5.1', [1/0] = 'Lua 5.4'},
 Egor>    [true]  = {[-1/0] = 'Lua 5.2', [1/0] = 'Lua 5.3'},
 Egor>    [1]     = 'LuaJIT'}
 Egor> local version = t[1] or t[f()==f()][1/'-0']

How about,

local f, t = function()return function()end end, {nil, -1,
  [false] = {[-1/0] = 'Lua 5.1', [1/0] = 'Lua 5.4'},
  [true]  = {[-1/0] = 'Lua 5.2', [1/0] = 'Lua 5.3'},
  [1]     = 'LuaJIT'}
print(t[1] or t[f()==f()][1/(t[2]*0)])

Not sure how reliably the t[2]*0 evaluates to -0 on 5.1/5.2, though. It
works on the few platforms I tried. (Using a constant -1 there doesn't
work.)

-- 
Andrew.