Skip to content

Add Lua 5.1 to rockspec#9

Open
javalikescript wants to merge 4 commits into
pocomane:masterfrom
javalikescript:add-lua-5-1-to-rockspec
Open

Add Lua 5.1 to rockspec#9
javalikescript wants to merge 4 commits into
pocomane:masterfrom
javalikescript:add-lua-5-1-to-rockspec

Conversation

@javalikescript
Copy link
Copy Markdown
Contributor

@javalikescript javalikescript commented May 14, 2026

Fix #8

@s-ol
Copy link
Copy Markdown

s-ol commented May 14, 2026

Hey, this is almost right but the define should switch at 5.2, not 5.3. Compiling for 5.2 as is it picks the lua 5.1 version and fails:

$ luarocks --lua-version=5.2 make luachild-scm-1.rockspec 
gcc -O2 -fPIC -I/usr/include/lua5.2 -c luachild_common.c -o luachild_common.o -DUSE_POSIX -I./
gcc -O2 -fPIC -I/usr/include/lua5.2 -c luachild_lua_5_3.c -o luachild_lua_5_3.o -DUSE_POSIX -I./
gcc -O2 -fPIC -I/usr/include/lua5.2 -c luachild_lua_5_1.c -o luachild_lua_5_1.o -DUSE_POSIX -I./
luachild_lua_5_1.c: In function ‘lua_value_length’:
luachild_lua_5_1.c:19:10: error: implicit declaration of function ‘lua_objlen’; did you mean ‘lua_len’? [-Wimplicit-function-declaration]
   19 |   return lua_objlen(L, index);
      |          ^~~~~~~~~~
      |          lua_len

Error: Build error: Failed compiling object luachild_lua_5_1.o

I'd suggest renaming luachild_lua_5_3.c to luachild_lua_5_2.c and adjusting the ifdefs as follows:

diff --git a/luachild_lua_5_1.c b/luachild_lua_5_1.c
index c4ca9de..bfdea1b 100644
--- a/luachild_lua_5_1.c
+++ b/luachild_lua_5_1.c
@@ -1,6 +1,6 @@
 #include "luachild.h"
 #ifdef USE_LUAPUC
-#if LUA_VERSION_NUM < 503
+#if LUA_VERSION_NUM < 502
 
 #include <stdio.h>
 #include <errno.h>
diff --git a/luachild_lua_5_3.c b/luachild_lua_5_2.c
similarity index 97%
rename from luachild_lua_5_3.c
rename to luachild_lua_5_2.c
index 24ee272..acde7d4 100644
--- a/luachild_lua_5_3.c
+++ b/luachild_lua_5_2.c
@@ -1,6 +1,6 @@
 #include "luachild.h"
 #ifdef USE_LUAPUC
-#if LUA_VERSION_NUM > 502
+#if LUA_VERSION_NUM >= 502
 
 #include <stdio.h>
 #include <errno.h>
diff --git a/luachild-scm-1.rockspec b/luachild-scm-1.rockspec
index 75a7efd..d2ce5a4 100644
--- a/luachild-scm-1.rockspec
+++ b/luachild-scm-1.rockspec
@@ -29,7 +29,7 @@ build = {
         ["luachild"] = {
           defines = { "USE_POSIX" },
           incdirs = { "./" },
-          sources = { "luachild_common.c", "luachild_lua_5_3.c", "luachild_lua_5_1.c", "luachild_luajit_2_1.c", "luachild_posix.c", "luachild_windows.c", }
+          sources = { "luachild_common.c", "luachild_lua_5_2.c", "luachild_lua_5_1.c", "luachild_luajit_2_1.c", "luachild_posix.c", "luachild_windows.c", }
         },
       },
     },
@@ -39,7 +39,7 @@ build = {
         ["luachild"] = {
           defines = { "USE_WINDOWS" },
           incdirs = { "./" },
-          sources = { "luachild_common.c", "luachild_lua_5_3.c", "luachild_lua_5_1.c", "luachild_luajit_2_1.c", "luachild_posix.c", "luachild_windows.c", }
+          sources = { "luachild_common.c", "luachild_lua_5_2.c", "luachild_lua_5_1.c", "luachild_luajit_2_1.c", "luachild_posix.c", "luachild_windows.c", }
         },
       },
     },

(the < / >= makes the mechanism clearer too, IMHO)

With this change applied, it builds all versions from Lua 5.1 to 5.5 for me.

Comment thread luachild_lua_5_3.c Outdated
#include "luachild.h"
#ifdef USE_LUAPUC
#if LUA_VERSION_NUM > 502
#if LUA_VERSION_NUM >= 503
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@javalikescript this should be >= 502, otherwise Lua 5.2 is left with no implementation at all

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lua 5.2 already works, just compile it as 5.3, there is no difference in the C API used by this library

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in commit 8500dc9

@javalikescript javalikescript marked this pull request as ready for review May 19, 2026 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Doesn't work with lua51

2 participants