如何在运行时检测是否正在运行Luajit或PUC Lua 5.1? [英] How can I detect at runtime if I am running Luajit or PUC Lua 5.1?
问题描述
我正在为我的Lua项目编写一些测试脚本,并且我想确保它们可以在可用的不同Lua版本下正确运行.由于我的单元测试框架配置不当会使用错误的Lua版本,因此我想特别安全,并在运行时检查测试运行的Lua版本.最好的方法是什么?
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?
我知道区分5.1和5.2的一种快速方法是检查_VERSION
全局值,但是如何区分常规的Lua 5.1和LuaJIT?
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?
推荐答案
Luajit用jit
模块扩展了标准库.这可能是检测其存在的更直接的方法:
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
这篇关于如何在运行时检测是否正在运行Luajit或PUC Lua 5.1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!