aboutsummaryrefslogtreecommitdiff
path: root/ldo.c
diff options
context:
space:
mode:
Diffstat (limited to 'ldo.c')
-rw-r--r--ldo.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/ldo.c b/ldo.c
index fa8d98b2..889cb34b 100644
--- a/ldo.c
+++ b/ldo.c
@@ -387,15 +387,17 @@ static void rethook (lua_State *L, CallInfo *ci, int nres) {
387** stack, below original 'func', so that 'luaD_precall' can call it. Raise 387** stack, below original 'func', so that 'luaD_precall' can call it. Raise
388** an error if there is no '__call' metafield. 388** an error if there is no '__call' metafield.
389*/ 389*/
390void luaD_tryfuncTM (lua_State *L, StkId func) { 390StkId luaD_tryfuncTM (lua_State *L, StkId func) {
391 const TValue *tm = luaT_gettmbyobj(L, s2v(func), TM_CALL); 391 const TValue *tm = luaT_gettmbyobj(L, s2v(func), TM_CALL);
392 StkId p; 392 StkId p;
393 checkstackGCp(L, 1, func); /* space for metamethod */
393 if (l_unlikely(ttisnil(tm))) 394 if (l_unlikely(ttisnil(tm)))
394 luaG_callerror(L, s2v(func)); /* nothing to call */ 395 luaG_callerror(L, s2v(func)); /* nothing to call */
395 for (p = L->top; p > func; p--) /* open space for metamethod */ 396 for (p = L->top; p > func; p--) /* open space for metamethod */
396 setobjs2s(L, p, p-1); 397 setobjs2s(L, p, p-1);
397 L->top++; /* stack space pre-allocated by the caller */ 398 L->top++; /* stack space pre-allocated by the caller */
398 setobj2s(L, func, tm); /* metamethod is the new function to be called */ 399 setobj2s(L, func, tm); /* metamethod is the new function to be called */
400 return func;
399} 401}
400 402
401 403
@@ -558,8 +560,7 @@ CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) {
558 return ci; 560 return ci;
559 } 561 }
560 default: { /* not a function */ 562 default: { /* not a function */
561 checkstackGCp(L, 1, func); /* space for metamethod */ 563 func = luaD_tryfuncTM(L, func); /* try to get '__call' metamethod */
562 luaD_tryfuncTM(L, func); /* try to get '__call' metamethod */
563 goto retry; /* try again with metamethod */ 564 goto retry; /* try again with metamethod */
564 } 565 }
565 } 566 }