In Lua, is there a function that will tell me what current version I'm running?
lua, version
Solution
There is global variable _VERSION (a string):
print(_VERSION)
-- Output
Lua 5.2
UPD : Other methods to distinguish between Lua versions:
if _ENV then
-- Lua 5.2
else
-- Lua 5.1
end
UPD2 :
--[=[
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'
--]]
print(version)
Problem
Subject says it all. I would like to know if my host interpreter is running Lua 5.2 or 5.1