From a30a6ceb5d7616bc135377b1dc507bd2eeeab876 Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Mon, 17 Jan 2022 08:29:13 +0100 Subject: [PATCH] app_lua: added internal alternative to luaL_openlib() - it was deprecated in Lua API, no longer available in newer versions [wip] --- src/modules/app_lua/app_lua_api.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/modules/app_lua/app_lua_api.c b/src/modules/app_lua/app_lua_api.c index 8b572d2382d..6dffde1119d 100644 --- a/src/modules/app_lua/app_lua_api.c +++ b/src/modules/app_lua/app_lua_api.c @@ -184,6 +184,34 @@ int sr_lua_reload_module(unsigned int reload) return 0; } +/** + * + */ +void ksr_luaL_openlib_mode(lua_State *L, const char *libname, + const luaL_Reg *lfuncs, int nup, int mode) +{ + if(mode) { + lua_getglobal(L, libname); + if (lua_isnil(L, -1)) { + lua_pop(L, 1); + lua_newtable(L); + } + } else { + lua_newtable(L); + } + luaL_setfuncs(L, lfuncs, 0); + lua_setglobal(L, libname); +} + +/** + * + */ +void ksr_luaL_openlib(lua_State *L, const char *libname, + const luaL_Reg *lfuncs, int nup) +{ + ksr_luaL_openlib_mode(L, libname, lfuncs, nup, 0); +} + /** * */