Skip to content

Commit

Permalink
app_lua_sr: support for lua 5.4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
miconda committed Jan 26, 2022
1 parent 74bcf6e commit 3b75ccb
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions src/modules/app_lua_sr/app_lua_sr_api.c
Expand Up @@ -45,8 +45,70 @@
#include "app_lua_sr_api.h"
#include "app_lua_sr_exp.h"

#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 504
#define luaL_openlib ksr_luaL_openlib
#endif


extern app_lua_api_t _app_lua_api;


#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 504
/**
*
*/
void ksr_luaL_openlib_mode(lua_State *L, const char *libname,
const luaL_Reg *lfuncs, int nup, int mode)
{
char modname[256];
char *submod = NULL;
int tidx = 0;
if(mode) {
/* support for registering 'module.submodule' functions
* - 'module' functions must be registered first */
if(strlen(libname)>254) {
LM_ERR("module name is too long [%s]\n", libname);
return;
}
strcpy(modname, libname);
submod = strchr(modname, '.');
if(submod != NULL) {
*submod = '\0';
submod++;
}
lua_getglobal(L, modname);
if (lua_isnil(L, -1)) {
if(submod != NULL) {
LM_ERR("main module not registered yet [%s]\n", libname);
return;
}
lua_pop(L, 1);
lua_newtable(L);
luaL_setfuncs(L, lfuncs, 0);
lua_setglobal(L, modname);
return;
}
tidx = lua_gettop(L);
lua_newtable(L);
luaL_setfuncs(L, lfuncs, 0);
lua_setfield(L, tidx, submod);
return;
}
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, 1);
}
#endif

/**
*
*/
Expand Down

0 comments on commit 3b75ccb

Please sign in to comment.