natecraddock / ziglua

Zig bindings for the Lua C API
MIT License
259 stars 34 forks source link

registerFns doesn't build when lang=lua54 #107

Open nurpax opened 2 hours ago

nurpax commented 2 hours ago

Looks like there's no luaL_findtable in Lua 5.4 so the registerFns function fails to build.

https://github.com/natecraddock/ziglua/blob/beb0b78de0307c0a4ba5edefcbbfa8d4e8957e72/src/lib.zig#L2813

nurpax commented 2 hours ago

Actually this was already failing to build when I chose lang=lua53 but I thought luaL_findtable was indeed removed in 5.4 and I was suspecting I saw some kind of an incremental build bug with Zig.

nurpax commented 2 hours ago

Yeah, I think it was still there in 5.3 but only when built for compat:

C:\Users\janne\dev\zig-ast\t>rg findtable
lua-5.3.6\src\lauxlib.c
855:static const char *luaL_findtable (lua_State *L, int idx,
899:  luaL_findtable(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE, 1);
904:    if (luaL_findtable(L, 0, modname, sizehint) != NULL)
/*
** {======================================================
** Compatibility with 5.1 module functions
** =======================================================
*/
#if defined(LUA_COMPAT_MODULE)

static const char *luaL_findtable (lua_State *L, int idx,
                                   const char *fname, int szhint) {
natecraddock commented 1 hour ago

This seems closely related to https://github.com/natecraddock/ziglua/issues/42

I think the issue here is that older versions of Lua use luaL_register while newer ones use luaL_newlib. Maybe what ziglua needs is a higher-level function that works the same for all versions of Lua?

Also makes me wonder how we should handle LUA_COMPAT_MODULE (if at all)