How can I detect at runtime if I run Luajit or PUC Lua 5.1?

I am writing several test scripts for my Lua project, and I want to make sure that they work correctly under different versions of Lua. Since my unit testing framework may use the wrong version of Lua, if I configured it incorrectly, I would like to be more secure and check at runtime which version of Lua my tests run on. What would be the best way to do this?

I know that a quick way to say 5.1 and 5.2 separately is to check globality _VERSION, but how can I talk about regular Lua 5.1 and LuaJIT?

+4
source share
1 answer

Luajit jit. , :

if type(jit) == 'table' then
   print(jit.version)  --LuaJIT 2.0.2
end
+11

All Articles