aboutsummaryrefslogtreecommitdiff
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
parent279c3a6961c60252f0368fdea889caf977f85fe0 (diff)
downloadlua-0b63d79b36790febd4c081bf8d6737df27529f8d.tar.gz
lua-0b63d79b36790febd4c081bf8d6737df27529f8d.tar.bz2
lua-0b63d79b36790febd4c081bf8d6737df27529f8d.zip
Details
- 'luaL_setfuncs' avoids creating closures for placeholders. - Fixed some warnings about unused values in comma expressions. - Comments.
-rw-r--r--lauxlib.c10
-rw-r--r--ldo.c2
-rw-r--r--liolib.c2
-rw-r--r--ltablib.c2
-rw-r--r--ltests.c8
5 files changed, 13 insertions, 11 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) {
898 luaL_checkstack(L, nup, "too many upvalues"); 898 luaL_checkstack(L, nup, "too many upvalues");
899 for (; l->name != NULL; l++) { /* fill the table with given functions */ 899 for (; l->name != NULL; l++) { /* fill the table with given functions */
900 int i; 900 int i;
901 for (i = 0; i < nup; i++) /* copy upvalues to the top */ 901 if (l->func == NULL) /* place holder? */
902 lua_pushvalue(L, -nup); 902 lua_pushboolean(L, 0);
903 lua_pushcclosure(L, l->func, nup); /* closure with those upvalues */ 903 else {
904 for (i = 0; i < nup; i++) /* copy upvalues to the top */
905 lua_pushvalue(L, -nup);
906 lua_pushcclosure(L, l->func, nup); /* closure with those upvalues */
907 }
904 lua_setfield(L, -(nup + 2), l->name); 908 lua_setfield(L, -(nup + 2), l->name);
905 } 909 }
906 lua_pop(L, nup); /* remove upvalues */ 910 lua_pop(L, nup); /* remove upvalues */
diff --git a/ldo.c b/ldo.c
index e9a88e9e..e7e76a65 100644
--- a/ldo.c
+++ b/ldo.c
@@ -669,7 +669,7 @@ LUA_API int lua_resume (lua_State *L, lua_State *from, int nargs,
669 else if (L->top - (L->ci->func + 1) == nargs) /* no function? */ 669 else if (L->top - (L->ci->func + 1) == nargs) /* no function? */
670 return resume_error(L, "cannot resume dead coroutine", nargs); 670 return resume_error(L, "cannot resume dead coroutine", nargs);
671 } 671 }
672 else if (L->status != LUA_YIELD) 672 else if (L->status != LUA_YIELD) /* ended with errors? */
673 return resume_error(L, "cannot resume dead coroutine", nargs); 673 return resume_error(L, "cannot resume dead coroutine", nargs);
674 if (from == NULL) 674 if (from == NULL)
675 L->nCcalls = 1; 675 L->nCcalls = 1;
diff --git a/liolib.c b/liolib.c
index 7d6d51e6..fa6a0939 100644
--- a/liolib.c
+++ b/liolib.c
@@ -39,7 +39,7 @@
39/* Check whether 'mode' matches '[rwa]%+?[L_MODEEXT]*' */ 39/* Check whether 'mode' matches '[rwa]%+?[L_MODEEXT]*' */
40static int l_checkmode (const char *mode) { 40static int l_checkmode (const char *mode) {
41 return (*mode != '\0' && strchr("rwa", *(mode++)) != NULL && 41 return (*mode != '\0' && strchr("rwa", *(mode++)) != NULL &&
42 (*mode != '+' || (++mode, 1)) && /* skip if char is '+' */ 42 (*mode != '+' || ((void)(++mode), 1)) && /* skip if char is '+' */
43 (strspn(mode, L_MODEEXT) == strlen(mode))); /* check extensions */ 43 (strspn(mode, L_MODEEXT) == strlen(mode))); /* check extensions */
44} 44}
45 45
diff --git a/ltablib.c b/ltablib.c
index a9169f9e..48a6bdfe 100644
--- a/ltablib.c
+++ b/ltablib.c
@@ -299,7 +299,7 @@ static IdxT partition (lua_State *L, IdxT lo, IdxT up) {
299 /* loop invariant: a[lo .. i] <= P <= a[j .. up] */ 299 /* loop invariant: a[lo .. i] <= P <= a[j .. up] */
300 for (;;) { 300 for (;;) {
301 /* next loop: repeat ++i while a[i] < P */ 301 /* next loop: repeat ++i while a[i] < P */
302 while (lua_geti(L, 1, ++i), sort_comp(L, -1, -2)) { 302 while ((void)lua_geti(L, 1, ++i), sort_comp(L, -1, -2)) {
303 if (i == up - 1) /* a[i] < P but a[up - 1] == P ?? */ 303 if (i == up - 1) /* a[i] < P but a[up - 1] == P ?? */
304 luaL_error(L, "invalid order function for sorting"); 304 luaL_error(L, "invalid order function for sorting");
305 lua_pop(L, 1); /* remove a[i] */ 305 lua_pop(L, 1); /* remove a[i] */
diff --git a/ltests.c b/ltests.c
index 7d441d1a..f786eeb3 100644
--- a/ltests.c
+++ b/ltests.c
@@ -51,9 +51,8 @@ static int runC (lua_State *L, lua_State *L1, const char *pc);
51 51
52 52
53static void setnameval (lua_State *L, const char *name, int val) { 53static void setnameval (lua_State *L, const char *name, int val) {
54 lua_pushstring(L, name);
55 lua_pushinteger(L, val); 54 lua_pushinteger(L, val);
56 lua_settable(L, -3); 55 lua_setfield(L, -2, name);
57} 56}
58 57
59 58
@@ -710,12 +709,11 @@ static void printstack (lua_State *L) {
710 709
711 710
712static int get_limits (lua_State *L) { 711static int get_limits (lua_State *L) {
713 lua_createtable(L, 0, 5); 712 lua_createtable(L, 0, 6);
714 setnameval(L, "BITS_INT", LUAI_BITSINT); 713 setnameval(L, "IS32INT", LUAI_IS32INT);
715 setnameval(L, "MAXARG_Ax", MAXARG_Ax); 714 setnameval(L, "MAXARG_Ax", MAXARG_Ax);
716 setnameval(L, "MAXARG_Bx", MAXARG_Bx); 715 setnameval(L, "MAXARG_Bx", MAXARG_Bx);
717 setnameval(L, "OFFSET_sBx", OFFSET_sBx); 716 setnameval(L, "OFFSET_sBx", OFFSET_sBx);
718 setnameval(L, "BITS_INT", LUAI_BITSINT);
719 setnameval(L, "LFPF", LFIELDS_PER_FLUSH); 717 setnameval(L, "LFPF", LFIELDS_PER_FLUSH);
720 setnameval(L, "NUM_OPCODES", NUM_OPCODES); 718 setnameval(L, "NUM_OPCODES", NUM_OPCODES);
721 return 1; 719 return 1;