lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



On 31.03.2021 at 23:14 Gé Weijers wrote:


The problem is that 'tail' is no longer a tail call. In the general case the file can only be closed after 'tail' returns, like in this convoluted example:

Correct me if I'm wrong but at https://github.com/lua/lua/blob/master/lparser.c#L1814 the tailcall is inserted. For that fs->bl->insidetbc needs to be zero. It is set at https://github.com/lua/lua/blob/master/lparser.c#L1710 in checktoclose called from localstat but not in the for loop case at https://github.com/lua/lua/blob/master/lparser.c#L1602. In for loop case the fs->bl->insidetbc is never set and therfore the call is a tailcall.

Second, could you explain why commenting `return tail()` out in my previous example yields
> ./lua test.lua
This should be called

while the output with the `return tail()` is
> ./lua test.lua
Why is this called?

shouldn't they be the same?

Regards,
Xmilia