From 55189b731a95eceb8dc32d82e5530751cc41012b Mon Sep 17 00:00:00 2001 From: "Juan C. Diaz" Date: Wed, 5 Aug 2026 19:35:06 -0700 Subject: [PATCH] Skip redundant luaL_setfuncs when linking against LuaJIT LuaJIT already provides luaL_setfuncs (declared in lauxlib.h, defined in its own lib_aux.c). Defining it again here causes a duplicate symbol at link time on platforms where LuaJIT is linked as a static library (e.g. macOS), since the archive member providing it still gets pulled in for other symbols. Guard the compat definition so it only compiles for vanilla PUC Lua 5.1, which lacks the symbol. --- src/l52util.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/l52util.c b/src/l52util.c index 6373687..4883a9e 100644 --- a/src/l52util.c +++ b/src/l52util.c @@ -13,6 +13,7 @@ #include #include /* for memset */ #include +#include /* for LUAJIT_VERSION: LuaJIT already provides luaL_setfuncs */ #if LUA_VERSION_NUM >= 502 @@ -31,8 +32,12 @@ void luaL_register (lua_State *L, const char *libname, const luaL_Reg *l){ #endif -#else +#else +#ifndef LUAJIT_VERSION +/* LuaJIT's own lib_aux.c already provides luaL_setfuncs (declared in + * lauxlib.h); defining it again here would collide at link time when + * LuaJIT is linked as a static library. Only needed for vanilla Lua 5.1. */ void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup){ luaL_checkstack(L, nup, "too many upvalues"); for (; l->name != NULL; l++) { /* fill the table with given functions */ @@ -44,6 +49,7 @@ void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup){ } lua_pop(L, nup); /* remove upvalues */ } +#endif void lua_rawgetp(lua_State *L, int index, const void *p){ index = lua_absindex(L, index);