lua-users home
lua-l archive

Re: A tricky way to determine Lua version

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


It was thus said that the Great Ulrich Schmidt once stated:
> 
> Am 21.05.2016 um 09:13 schrieb Sean Conner:
> >It was thus said that the Great Vadim A. Misbakh-Soloviov once stated:
> >>> Mine relies upon strings still having a metatable.
> >>But lacks luajit ;)
> >
> > Nah. If version is nil, it's LuaJIT.
> >
> > -spc (nil can't be a table key, see ... )
> 
> Thats all true. I still like Egors version because it is simple to use.
> (without nil tests.) and the results can be changed eg.
> 
> function needs_setfenv()
> local f, t = function() return function() end end, {nil,
> [false] = true, --'5.1',
> [true] = false, --'5.2',
> [1/'-0'] = false, --'5.3',
> [1] = true, --'JIT'
> }
> return t[1] or t[1/0] or t[f()==f()];
> end;
 Hmm ... okay, how about:
local version = ({Q="Lua 5.1",R="Lua 5.2",S="Lua 5.3"})[
 ("").dump(function() end):sub(5,5)] or "LuaJIT"
And you can change it just as easily:
local version = ({Q=true,R=false,S=false})[
 ("").dump(function() end):sub(5,5)] or true
 -spc (Okay, so a few comments might be nice ... 8-)

AltStyle によって変換されたページ (->オリジナル) /