24

All I know is how to do it from command line, that is the -v switch.

I need something like phpversion() or sys.version in python. Is that possible ?

rsk82
  • 28,217
  • 50
  • 150
  • 240

1 Answers1

38

As the duplicate question says, the standard way to get Lua version is:

print(_VERSION)

Anyway, _VERSION will contain a string like Lua 5.1, but it's not the same as lua -v, which outputs the whole version information including min version number like Lua 5.1.4

There is another way: calling lua -v directly:

io.popen("lua -v")
--Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio

Note that io.popen is not portable, but it should work in both Linux and Windows.

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
  • 3
    But for the latter I would need the location of lua executable file. On my system "lua" is not recogized as executable, not added to path. – rsk82 Aug 16 '13 at 08:59
  • I have Centos 6 with Lua 5.1.4 Presintalled. I have downloaded and install the following rpm (http://rpm.pbone.net/index.php3/stat/4/idpl/21884500/dir/centos_6/com/dba-lua-521-5.2.1-1.1.x86_64.rpm.html) and still shows Lua 5.1.4. I have not clear things about how to enable/install/patch Lua to version 5.2 on my Centos 6. I've read a little about RHEL will not update versions, but i wanna know if is there any way to make it work. Thank you. – m3nda Apr 05 '15 at 12:50
  • 3
    `file = io.popen('lua -v'); print(file:read())` for me on Lua 5.2 – d9k Feb 21 '16 at 15:57
  • On my console it shows "2013.2.0 r13768", what version is it? – Luke Vo May 14 '19 at 17:42