- in 'luaB_tonumber', do not need to "checkany" when argument
is a number.

- in 'lua_resume', the call to 'luaD_rawrunprotected' cannot return
a status equal to -1.
This commit is contained in:
Roberto Ierusalimschy 2018-12-11 11:54:14 -02:00
parent 51316f9df7
commit 3b06f983ae
2 changed files with 14 additions and 17 deletions

View File

@ -68,7 +68,6 @@ static const char *b_str2int (const char *s, int base, lua_Integer *pn) {
static int luaB_tonumber (lua_State *L) {
if (lua_isnoneornil(L, 2)) { /* standard conversion? */
luaL_checkany(L, 1);
if (lua_type(L, 1) == LUA_TNUMBER) { /* already a number? */
lua_settop(L, 1); /* yes; return it */
return 1;
@ -79,6 +78,7 @@ static int luaB_tonumber (lua_State *L) {
if (s != NULL && lua_stringtonumber(L, s) == l + 1)
return 1; /* successful conversion to number */
/* else not a number */
luaL_checkany(L, 1); /* (but there must be some parameter) */
}
}
else {

29
ldo.c
View File

@ -678,22 +678,19 @@ LUA_API int lua_resume (lua_State *L, lua_State *from, int nargs,
L->nny = 0; /* allow yields */
api_checknelems(L, (L->status == LUA_OK) ? nargs + 1 : nargs);
status = luaD_rawrunprotected(L, resume, &nargs);
if (unlikely(status == -1)) /* error calling 'lua_resume'? */
status = LUA_ERRRUN;
else { /* continue running after recoverable errors */
while (errorstatus(status) && recover(L, status)) {
/* unroll continuation */
status = luaD_rawrunprotected(L, unroll, &status);
}
if (likely(!errorstatus(status)))
lua_assert(status == L->status); /* normal end or yield */
else { /* unrecoverable error */
status = luaF_close(L, L->stack, status); /* close all upvalues */
L->status = cast_byte(status); /* mark thread as 'dead' */
luaD_seterrorobj(L, status, L->stack + 1); /* push error message */
L->ci = &L->base_ci; /* back to the original C level */
L->ci->top = L->top;
}
/* continue running after recoverable errors */
while (errorstatus(status) && recover(L, status)) {
/* unroll continuation */
status = luaD_rawrunprotected(L, unroll, &status);
}
if (likely(!errorstatus(status)))
lua_assert(status == L->status); /* normal end or yield */
else { /* unrecoverable error */
status = luaF_close(L, L->stack, status); /* close all upvalues */
L->status = cast_byte(status); /* mark thread as 'dead' */
luaD_seterrorobj(L, status, L->stack + 1); /* push error message */
L->ci = &L->base_ci; /* back to the original C level */
L->ci->top = L->top;
}
*nresults = (status == LUA_YIELD) ? L->ci->u2.nyield
: cast_int(L->top - (L->ci->func + 1));