lua-users home
lua-l archive

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


Ah!

I missed that rather important detail about an iterator function now returning *four* values, not three.

FWIW I think that is a significant change from 5.3 to 5.4 and really ought to be added to the “main changes” section in the 5.4.0 manual. 

The manual mentions that the semantics of the numeric “for” has changed so I really think it is worth mentioning this change in the generic “for” as well. Maybe say words something like this:

* generic for loop iteration now allows for automatic variable cleanup when the loop ends




On 14 Jun 2019, at 13:57, Sergey Zakharchenko <doublef.mobile@gmail.com> wrote:

Paul,

> In your example, does your scope() function absolutely guarantee that the file you opened in the call to scope() will synchronously and reliably be closed after the “end” of the for loop but before the final call to print()?

The 5.4 'for' loop does (we return the file as a closin value for it). The function itself can be implemented in different ways, that's just one of them. As long as it doesn't itself cause some error (out of memory constructing the table?), the guarantee should hold.

Best regards,

--
DoubleF