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

£可爱£侵袭症+ 提交于 2019-12-12 10:46:25

问题


I am writing some test scripts for my Lua project and I want to be sure that they run correctly under the different Lua versions available. Since my unit testing framework can use the wrong Lua version if I misconfigure it, I would like to be extra safe and check at runtime what Lua version my tests are running under. What would be the best way to do that?

I know that a quick way to tell 5.1 and 5.2 apart is to check the _VERSION global but how can I tell regular Lua 5.1 and LuaJIT apart?


回答1:


Luajit extends the standard library with a jit module. That is probably a more direct way to detect its presence:

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


来源:https://stackoverflow.com/questions/20335340/how-can-i-detect-at-runtime-if-i-am-running-luajit-or-puc-lua-5-1

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!