Fixed bug in tail calls of __call chains

A tail call of a __call chain (a __call metamethod that itself is
also not a function) was being perfomed as a regular call.
This commit is contained in:
Roberto Ierusalimschy
2019-10-28 15:58:07 -03:00
parent c12983cf8a
commit 7d526e75a7
2 changed files with 26 additions and 2 deletions

3
lvm.c
View File

@@ -1549,9 +1549,10 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
luaF_close(L, base, NOCLOSINGMETH);
lua_assert(base == ci->func + 1);
}
if (!ttisfunction(s2v(ra))) { /* not a function? */
while (!ttisfunction(s2v(ra))) { /* not a function? */
luaD_tryfuncTM(L, ra); /* try '__call' metamethod */
b++; /* there is now one extra argument */
checkstackp(L, 1, ra);
}
if (!ttisLclosure(s2v(ra))) { /* C function? */
luaD_call(L, ra, LUA_MULTRET); /* call it */