Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot build wxLua for Lua 5.2 #54

Closed
LesNewell-SheetCam opened this issue Jan 22, 2020 · 3 comments
Closed

Cannot build wxLua for Lua 5.2 #54

LesNewell-SheetCam opened this issue Jan 22, 2020 · 3 comments
Assignees

Comments

@LesNewell-SheetCam
Copy link

LesNewell-SheetCam commented Jan 22, 2020

If you try to build for Lua5.2 the build fails in bit.c, line 180. It expects a return value from lua_rawget but lua_rawget does not return a value in 5.2. This appears to only be available in 5.3+
I have attached a diff to fix the issue (bit.c.txt):

diff --git a/wxLua/modules/wxlua/bit.c b/wxLua/modules/wxlua/bit.c
index 1c37f86..bc9abe1 100644
--- a/wxLua/modules/wxlua/bit.c
+++ b/wxLua/modules/wxlua/bit.c
@@ -168,7 +168,7 @@ static const struct luaL_Reg bit_funcs[] = {
 */
 #define BAD_SAR		(bsar(-8, 2) != (SBits)-2)
 
-#if LUA_VERSION_NUM >= 502
+#if LUA_VERSION_NUM > 502
 static int libsize (const luaL_Reg *l) {
   int size = 0;
   for (; l && l->name; l++) size++;
@@ -212,7 +212,7 @@ LUALIB_API int luaopen_bit(lua_State *L)
       msg = "arithmetic right-shift broken";
     luaL_error(L, "bit library self-test failed (%s)", msg);
   }
-#if LUA_VERSION_NUM < 502
+#if LUA_VERSION_NUM <= 502
   luaL_register(L, "bit", bit_funcs);
 #else
   pushmodule(L, "bit", libsize(bit_funcs));  /* get/create library table */
@pkulchenko pkulchenko self-assigned this Jan 22, 2020
@pkulchenko
Copy link
Owner

@sheetcam, what's the actual error you are getting? There is no luaL_register in lua 5.2 unless you turn the compatibility settings on, so the change may not work in some of the cases.

I think the following patch should work with both Lua 5.2 and Lua 5.3:

diff --git a/wxLua/modules/wxlua/bit.c b/wxLua/modules/wxlua/bit.c
index 1c37f86..377d544 100644
--- a/wxLua/modules/wxlua/bit.c
+++ b/wxLua/modules/wxlua/bit.c
@@ -177,7 +177,8 @@ static int libsize (const luaL_Reg *l) {
 static void pushmodule (lua_State *L, const char *modname, int sizehint) {
   lua_pushglobaltable(L);
   lua_pushstring(L, modname);
-  if (lua_rawget(L, -2) != LUA_TNIL) {  /* no such field? */
+  lua_rawget(L, -2);
+  if (!lua_isnil(L, -1)) {
     luaL_error(L, "name conflict for module '%s'", modname);
   }
   lua_pop(L, 1);  /* remove this nil */

Can you apply it and let me know?

@LesNewell-SheetCam
Copy link
Author

I just built wxWidgets 3.1.3 with 2.8 compatibility enabled then used the cmake defaults apart from setting the Lua version to 5.2 and the build type to MinSizeRel.
Your change appears to build. I'll run some more tests later.

@pkulchenko
Copy link
Owner

@sheetcam, sounds good. I pushed the changes, but let me know if you run into any issues.

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

No branches or pull requests

2 participants