Implement support for Lua 5.1

This commit is contained in:
Robert Paprocki
2018-06-21 11:15:55 -07:00
committed by Victor Hora
parent eed6b5f86d
commit dee9898449
3 changed files with 40 additions and 15 deletions

View File

@@ -101,4 +101,29 @@ static const struct luaL_Reg mscLuaLib[] = {
} // namespace engine
} // namespace modsecurity
#ifdef WITH_LUA
#if defined LUA_VERSION_NUM && LUA_VERSION_NUM < 502
/*
** Adapted from Lua 5.2.0
*/
#define LUA_OK 0
static void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup) {
luaL_checkstack(L, nup + 1, "too many upvalues");
for (; l->name != NULL; l++) { /* fill the table with given functions */
int i;
lua_pushstring(L, l->name);
for (i = 0; i < nup; i++) /* copy upvalues to the top */
lua_pushvalue(L, -(nup + 1));
lua_pushcclosure(L, l->func, nup); /* closure with those upvalues */
lua_settable(L, -(nup + 3));
}
lua_pop(L, nup); /* remove upvalues */
}
#endif
#endif
#endif // SRC_ENGINE_LUA_H_