G'day,
Checking the version in the header file is a symptom of a
different need. (If people simply wanted the current Lua
version, they could simply execute `lua -v`, and parse the
one-line output, e.g. in POSIX/Bash:
$ LUA_VERSION_WITH_PATCHLEVEL="$(lua -v 2>&1 | cut -d ' ' -f 2)"
$ LUA_VERSION_NUM="$(echo "$LUA_VERSION_WITH_PATCHLEVEL" | cut -d '.' -f 1-2)"
This means that looking at _VERSION will not be sufficient, i.e.
$ lua -e "print(_VERSION)"
Lua 5.2
$ which lua
/usr/bin/lua
.)
I saw a comment by Hisham that laid out the nub of the problem:
There may be multiple lua.h and associated headers, for different
versions of Lua, in different paths. Therefore, a user
(especially an automated script) needs to somehow work through
candidate paths, and evaluate the Lua version API represented
by the header files in each path, until a suitable version+path
is found, or the script runs out of candidates.
If a mismatched header/library version combination is used, this
can lead to runtime defects, such as require() failing due to
incorrect symbols. Hisham found that a significant number of
the reports he received were due to (spurious, if handled
correctly) mismatches, and so he added the include-path search
code to cut down the chances of a mismatch occurring.
The way the candidate list is built is informed by an
inspection of the way different OSes handle versioning; two
examples are given here:
$ locate lua.h | grep -v hpp # Gentoo (edited)
/usr/include/lua5.1/lua.h
/usr/include/lua5.3/lua.h
/usr/include/lua5.4/lua.h
/usr/include/luajit-2.1/lua.h
/usr/include/texlua53/lua.h
/usr/include/texluajit/lua.h
/usr/local/include/lua.h
$ locate lua.h | grep -v hpp # Ubuntu 23.10 (lglicua)
/usr/include/lua/5.4/lua.h
Also, note that, in the Lua sources, there are variables in
the top-level Makefile that can tailor a Lua build to a
client's needs:
$ cat lua-5.4.7/Makefile
# == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT =======================
# [...]
# Where to install. The installation starts in the src and doc directories,
# so take care if INSTALL_TOP is not an absolute path. See the local target.
# You may want to make INSTALL_LMOD and INSTALL_CMOD consistent with
# LUA_ROOT, LUA_LDIR, and LUA_CDIR in luaconf.h.
INSTALL_TOP= /usr/local
INSTALL_BIN= $(INSTALL_TOP)/bin
INSTALL_INC= $(INSTALL_TOP)/include
INSTALL_LIB= $(INSTALL_TOP)/lib
INSTALL_MAN= $(INSTALL_TOP)/man/man1
INSTALL_LMOD= $(INSTALL_TOP)/share/lua/$V
INSTALL_CMOD= $(INSTALL_TOP)/lib/lua/$V
My gut feeling is that an extra file could be added to the
headers, with a simple NAME=Value one-liner syntax, in a format
similar to, e.g. "/etc/os-release" ("lua-release"?):
$ cat /etc/os-release # on Gentoo
NAME=Gentoo
ID=gentoo
PRETTY_NAME="Gentoo Linux"
ANSI_COLOR="1;32"
HOME_URL="
https://www.gentoo.org/"
SUPPORT_URL="
https://www.gentoo.org/support/"
BUG_REPORT_URL="
https://bugs.gentoo.org/"
VERSION_ID="2.15"
$ cat /etc/os-release # on Ubuntu 23.10
PRETTY_NAME="Ubuntu 23.10"
NAME="Ubuntu"
VERSION_ID="23.10"
VERSION="23.10 (Mantic Minotaur)"
VERSION_CODENAME=mantic
ID=ubuntu
ID_LIKE=debian
HOME_URL="
https://www.ubuntu.com/"
SUPPORT_URL="
https://help.ubuntu.com/"
BUG_REPORT_URL="
https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="
https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=mantic
LOGO=ubuntu-logo
I defer to people with more knowledge of the wider affected
software ecosystems as to how to proceed.
Hope this helps,
b