# HG changeset patch # User Matthew Wild # Date 1619198894 -3600 # Node ID ebb63b55bcc172e6d2d70034b5ee6976110b18f9 # Parent b20d4fce30956b6f005fe947bdd588fc70cb3d74 Use luaL_register on 5.1 to avoid reimplementing setfuncs diff -r b20d4fce3095 -r ebb63b55bcc1 src/lxplib.c --- a/src/lxplib.c Fri Apr 23 17:54:51 2021 +0100 +++ b/src/lxplib.c Fri Apr 23 18:28:14 2021 +0100 @@ -20,6 +20,7 @@ #if (LUA_VERSION_NUM == 501) #define lua_getuservalue(L, i) lua_getfenv(L, i) #define lua_setuservalue(L, i) lua_setfenv(L, i) +#define luaL_setfuncs(L, R, N) luaL_register(L, NULL, R) #endif #if !defined(lua_pushliteral) @@ -588,26 +589,6 @@ lua_settable (L, -3); } - -#if !defined LUA_VERSION_NUM || LUA_VERSION_NUM==501 -/* -** Adapted from Lua 5.2.0 -*/ -static void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) { - luaL_checkstack(L, nup, "too many upvalues"); - for (; l->name != NULL; l++) { /* fill the table with given functions */ - int i; - for (i = 0; i < nup; i++) /* copy upvalues to the top */ - lua_pushvalue(L, -nup); - lua_pushstring(L, l->name); - lua_pushcclosure(L, l->func, nup); /* closure with those upvalues */ - lua_settable(L, -(nup + 3)); - } - lua_pop(L, nup); /* remove upvalues */ -} -#endif - - int luaopen_lxp (lua_State *L) { luaL_newmetatable(L, ParserType);