From 0b63d79b36790febd4c081bf8d6737df27529f8d Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 13 May 2019 16:20:40 -0300 Subject: Details - 'luaL_setfuncs' avoids creating closures for placeholders. - Fixed some warnings about unused values in comma expressions. - Comments. --- lauxlib.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'lauxlib.c') diff --git a/lauxlib.c b/lauxlib.c index dfe501a7..89e53dc1 100644 --- a/lauxlib.c +++ b/lauxlib.c @@ -898,9 +898,13 @@ LUALIB_API 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_pushcclosure(L, l->func, nup); /* closure with those upvalues */ + if (l->func == NULL) /* place holder? */ + lua_pushboolean(L, 0); + else { + for (i = 0; i < nup; i++) /* copy upvalues to the top */ + lua_pushvalue(L, -nup); + lua_pushcclosure(L, l->func, nup); /* closure with those upvalues */ + } lua_setfield(L, -(nup + 2), l->name); } lua_pop(L, nup); /* remove upvalues */ -- cgit v1.2.3-55-g6feb