|
@ -387,15 +387,17 @@ static void rethook (lua_State *L, CallInfo *ci, int nres) { |
|
|
** stack, below original 'func', so that 'luaD_precall' can call it. Raise |
|
|
** stack, below original 'func', so that 'luaD_precall' can call it. Raise |
|
|
** an error if there is no '__call' metafield. |
|
|
** an error if there is no '__call' metafield. |
|
|
*/ |
|
|
*/ |
|
|
void luaD_tryfuncTM (lua_State *L, StkId func) { |
|
|
StkId luaD_tryfuncTM (lua_State *L, StkId func) { |
|
|
const TValue *tm = luaT_gettmbyobj(L, s2v(func), TM_CALL); |
|
|
const TValue *tm = luaT_gettmbyobj(L, s2v(func), TM_CALL); |
|
|
StkId p; |
|
|
StkId p; |
|
|
|
|
|
checkstackGCp(L, 1, func); /* space for metamethod */ |
|
|
if (l_unlikely(ttisnil(tm))) |
|
|
if (l_unlikely(ttisnil(tm))) |
|
|
luaG_callerror(L, s2v(func)); /* nothing to call */ |
|
|
luaG_callerror(L, s2v(func)); /* nothing to call */ |
|
|
for (p = L->top; p > func; p--) /* open space for metamethod */ |
|
|
for (p = L->top; p > func; p--) /* open space for metamethod */ |
|
|
setobjs2s(L, p, p-1); |
|
|
setobjs2s(L, p, p-1); |
|
|
L->top++; /* stack space pre-allocated by the caller */ |
|
|
L->top++; /* stack space pre-allocated by the caller */ |
|
|
setobj2s(L, func, tm); /* metamethod is the new function to be called */ |
|
|
setobj2s(L, func, tm); /* metamethod is the new function to be called */ |
|
|
|
|
|
return func; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -558,8 +560,7 @@ CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) { |
|
|
return ci; |
|
|
return ci; |
|
|
} |
|
|
} |
|
|
default: { /* not a function */ |
|
|
default: { /* not a function */ |
|
|
checkstackGCp(L, 1, func); /* space for metamethod */ |
|
|
func = luaD_tryfuncTM(L, func); /* try to get '__call' metamethod */ |
|
|
luaD_tryfuncTM(L, func); /* try to get '__call' metamethod */ |
|
|
|
|
|
goto retry; /* try again with metamethod */ |
|
|
goto retry; /* try again with metamethod */ |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|