diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2021-08-18 12:05:06 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2021-08-18 12:05:06 -0300 |
| commit | 91673a8ec0ae55e188a790bd2dfdc99246adf20e (patch) | |
| tree | 4370ab4d6fa5127cc6bb44a1dfa62ea5eca8ff88 /ldo.c | |
| parent | 41871f1803770305f182f56cbd22a336c5236a19 (diff) | |
| download | lua-91673a8ec0ae55e188a790bd2dfdc99246adf20e.tar.gz lua-91673a8ec0ae55e188a790bd2dfdc99246adf20e.tar.bz2 lua-91673a8ec0ae55e188a790bd2dfdc99246adf20e.zip | |
'luaD_tryfuncTM' checks stack space by itself
Diffstat (limited to 'ldo.c')
| -rw-r--r-- | ldo.c | 7 |
1 files changed, 4 insertions, 3 deletions
| @@ -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 | */ |
| 390 | void luaD_tryfuncTM (lua_State *L, StkId func) { | 390 | StkId 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 | } |
