lua-users home
lua-l archive

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


2013/4/30 Thijs Schreijer <thijs@thijsschreijer.nl>:


> PS. A good utility function to detect the runtime would be nice
> (5.1, 5.2, LuaJit 1/2, any others?), to circumvent the issue mentioned
> by Dirk (checking on getfenv)

The start of string.dump(load"") contains a fingerprint.

…/var$ lua5.1
Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> return string.dump(loadstring""):sub(2,4)
Lua
> return math.floor(string.dump(loadstring""):sub(5,5):byte()/16)
5
> return string.dump(loadstring""):sub(5,5):byte()%16
1
>
…/var$ lua
Lua 5.2.2  Copyright (C) 1994-2013 Lua.org, PUC-Rio
> return string.dump(loadstring""):sub(2,4)
Lua
> return math.floor(string.dump(loadstring""):sub(5,5):byte()/16)
5
> return string.dump(loadstring""):sub(5,5):byte()%16
2
>
…/var$ luajit
LuaJIT 2.0.0 -- Copyright (C) 2005-2012 Mike Pall. http://luajit.org/
JIT: ON CMOV SSE2 SSE3 fold cse dce fwd dse narrow loop abc sink fuse
> return string.dump(loadstring""):sub(2,3)
LJ
>