[BREAKING] Add compat with Lua >=5.2

The luaocc library is no longer put into the global namespace
master
yw05 2021-03-29 08:38:08 +02:00
parent 5ba0606459
commit 4bb8129eec
3 changed files with 17 additions and 9 deletions

View File

@ -2,7 +2,10 @@ test:
stage: test stage: test
image: archlinux image: archlinux
script: script:
- pacman -Syu --noconfirm luarocks lua51 gcc opencc - pacman -Syu --noconfirm luarocks gcc opencc lua51 lua52 lua53 lua
- luarocks install --lua-version 5.1 busted - for i in 5.1 5.2 5.3 5.4; do
- luarocks make --lua-version 5.1 - luarocks install --lua-version $i busted
- busted busted_unittest.lua - luarocks make --lua-version $i
- busted busted_unittest.lua
- luarocks remove --lua-version $i busted
- done

View File

@ -10,7 +10,7 @@ description = {
license = "Apache" license = "Apache"
} }
dependencies = { dependencies = {
"lua ~> 5.1" "lua >= 5.1 <= 5.4"
} }
external_dependencies = { external_dependencies = {
OPENCC = { OPENCC = {

13
main.c
View File

@ -35,21 +35,26 @@ static int L_close(lua_State *L) {
return 0; return 0;
} }
static const struct luaL_reg occlib[] = { static const struct luaL_Reg occlib[] = {
{"open", L_open}, {"open", L_open},
{"convert", L_convert}, {"convert", L_convert},
{NULL, NULL} {NULL, NULL}
}; };
static const struct luaL_reg occmt[] = { static const struct luaL_Reg occmt[] = {
{"__call", L_convert}, {"__call", L_convert},
{"__gc", L_close}, {"__gc", L_close},
{NULL, NULL} {NULL, NULL}
}; };
#if (LUA_VERSION_NUM >= 502)
#define luaL_register(L, _, l) luaL_setfuncs(L, l, 0)
#endif
int luaopen_luaocc(lua_State *L) { int luaopen_luaocc(lua_State *L) {
luaL_newmetatable(L, "luaocc"); luaL_newmetatable(L, "luaocc");
luaL_register(L, NULL, occmt); luaL_register(L, NULL, occmt);
luaL_register(L, "luaocc", occlib); lua_newtable(L);
luaL_register(L, NULL, occlib);
return 1; return 1;
} }