VERSION

From codeTank

Jump to: navigation, search

Contents

Description

_VERSION is a string that contains the current version of Lua. The format of this string is determined by Lua.org. Currently, the value is "Lua 5.1".

Example

print(_VERSION)     -- output: Lua 5.1

-- extract the sub-version numbers using pattern matching
local ver = {}
local w = ""
for w in string.gmatch(_VERSION, "%d+") do
    ver[table.getn(ver) + 1] = tonumber(w);
end

print("Maj = " .. ver[1]) -- output: Maj = 5
print("Min = " .. ver[2]) -- output: Min = 1

Extra Notes

Please be aware that this is different than the _LUA_VERSION value, which is the Brain Damage mechanism for detecting the Lua version. _VERSION will only return the major and minor numbers, whereas _LUA_VERSION is explicitly defined to return a revision number if it exists.

E.g., _LUA_VERSION = "Lua 5.1.2", but _VERSION = "Lua 5.1"

See Also

Personal tools