summaryrefslogtreecommitdiff
path: root/lauxlib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-05-13 16:20:40 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-05-13 16:20:40 -0300
commit0b63d79b36790febd4c081bf8d6737df27529f8d (patch)
treea59ac63d213b00fb0dcaaa65f6d24526c4f260f7 /lauxlib.c
parent279c3a6961c60252f0368fdea889caf977f85fe0 (diff)
downloadlua-github-0b63d79b36790febd4c081bf8d6737df27529f8d.tar.gz
Details
- 'luaL_setfuncs' avoids creating closures for placeholders. - Fixed some warnings about unused values in comma expressions. - Comments.
Diffstat (limited to 'lauxlib.c')
-rw-r--r--lauxlib.c10
1 files changed, 7 insertions, 3 deletions
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 */