[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: A tricky way to determine Lua version
- From: Egor Skriptunoff <egor.skriptunoff@...>
- Date: Sat, 21 May 2016 08:18:21 +0300
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()]
The curious fact about this program is that it doesn't depend on anything
that can be changed.
It does not use any standard library function or any global variable
(as they may be withdrawn from sandboxed environment).
It does not rely on the name of "_ENV" upvalue
(as it can be renamed when Lua is being built).
-- Egor