Use luaL_register on 5.1 to avoid reimplementing setfuncs

Fri, 23 Apr 2021 18:28:14 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Fri, 23 Apr 2021 18:28:14 +0100
changeset 31
ebb63b55bcc1
parent 30
b20d4fce3095
child 32
73adc42f35ce

Use luaL_register on 5.1 to avoid reimplementing setfuncs

src/lxplib.c file | annotate | diff | comparison | revisions
--- 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);
 

mercurial