Browse Source

Details

- 'luaL_setfuncs' avoids creating closures for placeholders.
- Fixed some warnings about unused values in comma expressions.
- Comments.
pull/23/head
Roberto Ierusalimschy 6 years ago
parent
commit
0b63d79b36
  1. 10
      lauxlib.c
  2. 2
      ldo.c
  3. 2
      liolib.c
  4. 2
      ltablib.c
  5. 8
      ltests.c

10
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"); luaL_checkstack(L, nup, "too many upvalues");
for (; l->name != NULL; l++) { /* fill the table with given functions */ for (; l->name != NULL; l++) { /* fill the table with given functions */
int i; int i;
for (i = 0; i < nup; i++) /* copy upvalues to the top */ if (l->func == NULL) /* place holder? */
lua_pushvalue(L, -nup); lua_pushboolean(L, 0);
lua_pushcclosure(L, l->func, nup); /* closure with those upvalues */ 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_setfield(L, -(nup + 2), l->name);
} }
lua_pop(L, nup); /* remove upvalues */ lua_pop(L, nup); /* remove upvalues */

2
ldo.c

@ -669,7 +669,7 @@ LUA_API int lua_resume (lua_State *L, lua_State *from, int nargs,
else if (L->top - (L->ci->func + 1) == nargs) /* no function? */ else if (L->top - (L->ci->func + 1) == nargs) /* no function? */
return resume_error(L, "cannot resume dead coroutine", nargs); 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); return resume_error(L, "cannot resume dead coroutine", nargs);
if (from == NULL) if (from == NULL)
L->nCcalls = 1; L->nCcalls = 1;

2
liolib.c

@ -39,7 +39,7 @@
/* Check whether 'mode' matches '[rwa]%+?[L_MODEEXT]*' */ /* Check whether 'mode' matches '[rwa]%+?[L_MODEEXT]*' */
static int l_checkmode (const char *mode) { static int l_checkmode (const char *mode) {
return (*mode != '\0' && strchr("rwa", *(mode++)) != NULL && 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 */ (strspn(mode, L_MODEEXT) == strlen(mode))); /* check extensions */
} }

2
ltablib.c

@ -299,7 +299,7 @@ static IdxT partition (lua_State *L, IdxT lo, IdxT up) {
/* loop invariant: a[lo .. i] <= P <= a[j .. up] */ /* loop invariant: a[lo .. i] <= P <= a[j .. up] */
for (;;) { for (;;) {
/* next loop: repeat ++i while a[i] < P */ /* 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 ?? */ if (i == up - 1) /* a[i] < P but a[up - 1] == P ?? */
luaL_error(L, "invalid order function for sorting"); luaL_error(L, "invalid order function for sorting");
lua_pop(L, 1); /* remove a[i] */ lua_pop(L, 1); /* remove a[i] */

8
ltests.c

@ -51,9 +51,8 @@ static int runC (lua_State *L, lua_State *L1, const char *pc);
static void setnameval (lua_State *L, const char *name, int val) { static void setnameval (lua_State *L, const char *name, int val) {
lua_pushstring(L, name);
lua_pushinteger(L, val); lua_pushinteger(L, val);
lua_settable(L, -3); lua_setfield(L, -2, name);
} }
@ -710,12 +709,11 @@ static void printstack (lua_State *L) {
static int get_limits (lua_State *L) { static int get_limits (lua_State *L) {
lua_createtable(L, 0, 5); lua_createtable(L, 0, 6);
setnameval(L, "BITS_INT", LUAI_BITSINT); setnameval(L, "IS32INT", LUAI_IS32INT);
setnameval(L, "MAXARG_Ax", MAXARG_Ax); setnameval(L, "MAXARG_Ax", MAXARG_Ax);
setnameval(L, "MAXARG_Bx", MAXARG_Bx); setnameval(L, "MAXARG_Bx", MAXARG_Bx);
setnameval(L, "OFFSET_sBx", OFFSET_sBx); setnameval(L, "OFFSET_sBx", OFFSET_sBx);
setnameval(L, "BITS_INT", LUAI_BITSINT);
setnameval(L, "LFPF", LFIELDS_PER_FLUSH); setnameval(L, "LFPF", LFIELDS_PER_FLUSH);
setnameval(L, "NUM_OPCODES", NUM_OPCODES); setnameval(L, "NUM_OPCODES", NUM_OPCODES);
return 1; return 1;

Loading…
Cancel
Save