mirror of https://github.com/lua/lua
no need to ensure any stack space for panic function + some changes
in 'tryfuncTM' (small simplification)
This commit is contained in:
parent
be87789a6c
commit
9a38c08011
28
ldo.c
28
ldo.c
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: ldo.c,v 2.133 2014/11/02 19:33:33 roberto Exp roberto $
|
||||
** $Id: ldo.c,v 2.134 2014/11/10 17:42:04 roberto Exp roberto $
|
||||
** Stack and Call structure of Lua
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -123,9 +123,9 @@ l_noret luaD_throw (lua_State *L, int errcode) {
|
|||
if (g->panic) { /* panic function? */
|
||||
seterrorobj(L, errcode, L->top); /* assume EXTRA_STACK */
|
||||
if (L->ci->top < L->top)
|
||||
L->ci->top = L->top + 2;
|
||||
L->ci->top = L->top; /* pushing msg. can break this invariant */
|
||||
lua_unlock(L);
|
||||
g->panic(L); /* call it (last chance to jump out) */
|
||||
g->panic(L); /* call panic function (last chance to jump out) */
|
||||
}
|
||||
abort();
|
||||
}
|
||||
|
@ -289,24 +289,18 @@ static StkId adjust_varargs (lua_State *L, Proto *p, int actual) {
|
|||
/*
|
||||
** Check whether __call metafield of 'func' is a function. If so, put
|
||||
** it in stack below original 'func' so that 'luaD_precall' can call
|
||||
** it. Raise an error if __call metafield is not a function. (The
|
||||
** check 'luaD_checkstack' avoids problems of errors in tag methods,
|
||||
** because both tag methods and error messages may need EXTRA_STACK.)
|
||||
** it. Raise an error if __call metafield is not a function.
|
||||
*/
|
||||
static StkId tryfuncTM (lua_State *L, StkId func) {
|
||||
static void tryfuncTM (lua_State *L, StkId func) {
|
||||
const TValue *tm = luaT_gettmbyobj(L, func, TM_CALL);
|
||||
StkId p;
|
||||
ptrdiff_t funcr = savestack(L, func);
|
||||
if (!ttisfunction(tm)) {
|
||||
luaD_checkstack(L, 1);
|
||||
if (!ttisfunction(tm))
|
||||
luaG_typeerror(L, func, "call");
|
||||
}
|
||||
/* Open a hole inside the stack at 'func' */
|
||||
for (p = L->top; p > func; p--) setobjs2s(L, p, p-1);
|
||||
incr_top(L);
|
||||
func = restorestack(L, funcr); /* previous call may change stack */
|
||||
for (p = L->top; p > func; p--)
|
||||
setobjs2s(L, p, p-1);
|
||||
L->top++; /* slot ensured by caller */
|
||||
setobj2s(L, func, tm); /* tag method is the new function to be called */
|
||||
return func;
|
||||
}
|
||||
|
||||
|
||||
|
@ -376,7 +370,9 @@ int luaD_precall (lua_State *L, StkId func, int nresults) {
|
|||
return 0;
|
||||
}
|
||||
default: { /* not a function */
|
||||
func = tryfuncTM(L, func); /* retry with 'function' tag method */
|
||||
luaD_checkstack(L, 1); /* ensure space for metamethod */
|
||||
func = restorestack(L, funcr); /* previous call may change stack */
|
||||
tryfuncTM(L, func); /* try to get '__call' metamethod */
|
||||
return luaD_precall(L, func, nresults); /* now it must be a function */
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue