Currently, `LUA_LDIR` and `LUA_CDIR` are hardcoded in `luaconf.h` to
`share/lua/` and `lib/lua/` relative to `LUA_ROOT`. This structure
limits the ability to install Lua C extensions into system-specific
directories, such as `/usr/lib64` on compatible Linux distributions,
without modifying the source code directly.
This commit modifies `luaconf.h` to check if `LUA_LDIR` or `LUA_CDIR`
are already defined (e.g., via compiler flags like
`-DLUA_CDIR="/usr/lib64/lua/5.5/"`). If defined, these values are
stringified and used; otherwise, the default paths are preserved. This
change improves build system flexibility and multi-arch support.
Signed-off-by: Matěj Cepl <
mc...@cepl.eu>
---
luaconf.h | 25 ++++++++++++++++++++-----
1 file changed, 20 insertions(+), 5 deletions(-)
diff --git a/luaconf.h b/luaconf.h
index 96a77802..4fccaa64 100644
--- a/luaconf.h
+++ b/luaconf.h
@@ -224,8 +224,8 @@
#if !defined(LUA_PATH_DEFAULT)
#define LUA_PATH_DEFAULT \
- LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;" \
- LUA_CDIR"?.lua;" LUA_CDIR"?\\init.lua;" \
+ LUA_LDIR_PATH"?.lua;" LUA_LDIR_PATH"?/init.lua;" \
+ LUA_CDIR_PATH"?.lua;" LUA_CDIR_PATH"?/init.lua;" \
LUA_SHRDIR"?.lua;" LUA_SHRDIR"?\\init.lua;" \
".\\?.lua;" ".\\?\\init.lua"
#endif
@@ -239,9 +239,24 @@
#else /* }{ */
+#ifndef LUA_ROOT
#define LUA_ROOT "/usr/local/"
-#define LUA_LDIR LUA_ROOT "share/lua/" LUA_VDIR "/"
-#define LUA_CDIR LUA_ROOT "lib/lua/" LUA_VDIR "/"
+#endif
+
+#define LUA_STR_HELPER(x) #x
+#define LUA_STR(x) LUA_STR_HELPER(x)
+
+#ifdef LUA_LDIR
+#define LUA_LDIR_PATH LUA_STR(LUA_LDIR)
+#else
+#define LUA_LDIR_PATH LUA_ROOT "share/lua/" LUA_VDIR "/"
+#endif
+
+#ifdef LUA_CDIR
+#define LUA_CDIR_PATH LUA_STR(LUA_CDIR)
+#else
+#define LUA_CDIR_PATH LUA_ROOT "lib/lua/" LUA_VDIR "/"
+#endif
#if !defined(LUA_PATH_DEFAULT)
#define LUA_PATH_DEFAULT \
@@ -252,7 +267,7 @@
#if !defined(LUA_CPATH_DEFAULT)
#define LUA_CPATH_DEFAULT \
- LUA_CDIR"?.so;" LUA_CDIR"loadall.so;" "./?.so"
+ LUA_CDIR_PATH"?.so;" LUA_CDIR_PATH"loadall.so;" "./?.so"
#endif
#endif /* } */
--
2.52.0