[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
image: archlinux
script:
- pacman -Syu --noconfirm luarocks lua51 gcc opencc
- luarocks install --lua-version 5.1 busted
- luarocks make --lua-version 5.1
- busted busted_unittest.lua
- pacman -Syu --noconfirm luarocks gcc opencc lua51 lua52 lua53 lua
- for i in 5.1 5.2 5.3 5.4; do
- luarocks install --lua-version $i busted
- 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"
}
dependencies = {
"lua ~> 5.1"
"lua >= 5.1 <= 5.4"
}
external_dependencies = {
OPENCC = {

13
main.c
View File

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