On Fri, Jun 29, 2018 at 1:32 PM, Thijs Schreijer wrote:
>> --[=[
>> 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'
>> --]]
It also misses detection of LuaJIT’s 5.2 compatibility flag
The main idea of this "version detector" is to be undeceivable by sandboxing.
A sandboxing environment could change any globals, so this script doesn't rely on globals and libraries.
I don't know how to check for LuaJIT 5.2 compatibility in the same robust way.
I can suggest the following script which depends on "loadstring" global variable:
if version == 'LuaJIT' then
version = version..(loadstring'b=0b0' and ' 2.1' or ' 2.0')
version = version..(loadstring';' and ' with LUA52COMPAT' or '')
end