I'm working with a library, lua-zip  that is a binding to libzip .
I would like to make sure that the library remains compatible with
Lua 5.1, 5.2, and 5.3, if possible.
lua-zip was written for Lua 5.1, and does not compile under Lua 5.2,
5.3 because the following functions are missing:
lua_equal, luaL_checkint, lua_objlen, luaL_register
I understand that I can use compatibility macros or replace lua_equal,
luaL_checkint, lua_objlen myself, so they are not the problem.
The problem is with luaL_register. With 5.3, it is an alias for
luaL_openlib, that is exported only if LUA_COMPAT_MODULE is defined
during compilation, which neither Debian nor Homebrew seem to do.
So, when I do `local zip = require "brimworks.zip"`, I get this
/usr/local/share/lua/5.3/luarocks/loader.lua:153: error loading module
'brimworks.zip' from file
[C]: in local 'a_loader'
/usr/local/share/lua/5.3/luarocks/loader.lua:153: in function
[C]: in function 'require'
stdin:1: in main chunk
[C]: in ?
What would be a good, and clean way to fix this ? Should I copy/paste
the code from lauxlib? How can I disable this compatibility code if
I'm compiling for 5.2 or lower?
Antonin> The problem is with luaL_register. With 5.3, it is an alias
Antonin> for luaL_openlib, that is exported only if LUA_COMPAT_MODULE
Antonin> is defined during compilation, which neither Debian nor
Antonin> Homebrew seem to do.
I did not update it to Lua 5.3 but I think code targeted at Lua 5.2
will compile smoothly with Lua 5.3. I hope it could be helpful.
Em dom, 7 de abr de 2019 às 15:41, Andrew Gierth
<[hidden email]> escreveu:
> >>>>> "Antonin" == Antonin Décimo <[hidden email]> writes:
> Antonin> The problem is with luaL_register. With 5.3, it is an alias
> Antonin> for luaL_openlib, that is exported only if LUA_COMPAT_MODULE
> Antonin> is defined during compilation, which neither Debian nor
> Antonin> Homebrew seem to do.
> How about,
> #if LUA_VERSION_NUM < 502
> #define luaL_newlib(L_,f_) (lua_newtable(L_), luaL_register((L_),NULL,(f_)))
> and use luaL_newlib(L, fns); where you currently have newtable/register
All the checks may completely be an overkill, but I think it's the
best I can do. It seems to work without troubles on Debian with all
available versions of Lua, and on Homebrew too. (Also this code was
upstreamed and tagged as new version, so please^3 don't tell me
there's an obvious bug with this).