[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: To-be-closed variables from Lua's existing mechanisms?
- From: Roberto Ierusalimschy <roberto@...>
- Date: Mon, 22 Nov 2021 16:59:25 -0300
> Since Lua is a language that provides basic mechanisms instead of builtin
> high-level constructs, I am wondering: why were to-be-closed variables
> given special language-level support? I think it should be possible to
> implement the equivalent using closures:
>
> [...]
>
> I left out some details, but I'm assuming that something like the above
> could be made to work. If not, what am I missing? But either way, I am
> wondering what went into the decision to give to-be-closed variables
> language-level support instead of having users construct them from Lua's
> mechanisms?
Although "something like the above" could be made to work, it is
hard to be sure it really covers all corners. A basic idea for
to-be-closed variables was to give the user a mostly bulletproof way
to garantee that the resource will be released.
Another thing that had great weight in the decision was its
interaction with coroutines and also with for-loops. For coroutines,
in particular, it provides a way to finalize an interrupted coroutine
that is quite tricky to ensure in other ways.
-- Roberto