Details
- 'luaL_setfuncs' avoids creating closures for placeholders.
- Fixed some warnings about unused values in comma expressions.
- Comments.
diff --git a/lauxlib.c b/lauxlib.c
index dfe501a..89e53dc 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -898,9 +898,13 @@
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 */
diff --git a/ldo.c b/ldo.c
index e9a88e9..e7e76a6 100644
--- a/ldo.c
+++ b/ldo.c
@@ -669,7 +669,7 @@
else if (L->top - (L->ci->func + 1) == nargs) /* no function? */
return resume_error(L, "cannot resume dead coroutine", nargs);
}
- else if (L->status != LUA_YIELD)
+ else if (L->status != LUA_YIELD) /* ended with errors? */
return resume_error(L, "cannot resume dead coroutine", nargs);
if (from == NULL)
L->nCcalls = 1;
diff --git a/liolib.c b/liolib.c
index 7d6d51e..fa6a093 100644
--- a/liolib.c
+++ b/liolib.c
@@ -39,7 +39,7 @@
/* Check whether 'mode' matches '[rwa]%+?[L_MODEEXT]*' */
static int l_checkmode (const char *mode) {
return (*mode != '\0' && strchr("rwa", *(mode++)) != NULL &&
- (*mode != '+' || (++mode, 1)) && /* skip if char is '+' */
+ (*mode != '+' || ((void)(++mode), 1)) && /* skip if char is '+' */
(strspn(mode, L_MODEEXT) == strlen(mode))); /* check extensions */
}
diff --git a/ltablib.c b/ltablib.c
index a9169f9..48a6bdf 100644
--- a/ltablib.c
+++ b/ltablib.c
@@ -299,7 +299,7 @@
/* loop invariant: a[lo .. i] <= P <= a[j .. up] */
for (;;) {
/* next loop: repeat ++i while a[i] < P */
- while (lua_geti(L, 1, ++i), sort_comp(L, -1, -2)) {
+ while ((void)lua_geti(L, 1, ++i), sort_comp(L, -1, -2)) {
if (i == up - 1) /* a[i] < P but a[up - 1] == P ?? */
luaL_error(L, "invalid order function for sorting");
lua_pop(L, 1); /* remove a[i] */
diff --git a/ltests.c b/ltests.c
index 7d441d1..f786eeb 100644
--- a/ltests.c
+++ b/ltests.c
@@ -51,9 +51,8 @@
static void setnameval (lua_State *L, const char *name, int val) {
- lua_pushstring(L, name);
lua_pushinteger(L, val);
- lua_settable(L, -3);
+ lua_setfield(L, -2, name);
}
@@ -710,12 +709,11 @@
static int get_limits (lua_State *L) {
- lua_createtable(L, 0, 5);
- setnameval(L, "BITS_INT", LUAI_BITSINT);
+ lua_createtable(L, 0, 6);
+ setnameval(L, "IS32INT", LUAI_IS32INT);
setnameval(L, "MAXARG_Ax", MAXARG_Ax);
setnameval(L, "MAXARG_Bx", MAXARG_Bx);
setnameval(L, "OFFSET_sBx", OFFSET_sBx);
- setnameval(L, "BITS_INT", LUAI_BITSINT);
setnameval(L, "LFPF", LFIELDS_PER_FLUSH);
setnameval(L, "NUM_OPCODES", NUM_OPCODES);
return 1;