lua-users home
lua-l archive

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


On Sat, 15 Jun 2019 at 19:35, Francisco Olarte <folarte@peoplecall.com> wrote:
>
> do
>   local original = generate_value_with_toclose_metatmethod()
>   ...
>   local <toclose> copy1 = original
>   ...
>   local <toclose> copy2 = original
>   ...
> end --
>
> Will __toclose be called twice on the valuewhen reaching end ? ( I
> expect it to be )
>

I haven't checked but the manual should state that the __close()
metamethod needs to be idempotent. It needs to track the state of the
resource so that if it is called multiple times, it still behaves
correctly.
This is a well known pattern that most close() operations need to follow.
Another aspect is that as is recommended in most other languages,
raising errors in finalizers and close operations is usually a bad
idea. Perhaps some advice on this should also be in the manual.

Regards