[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: To-be-closed variables from Lua's existing mechanisms?
- From: David Sicilia <dpsicilia@...>
- Date: Mon, 22 Nov 2021 17:57:28 -0500
Thanks; I guess the use case with coroutines would indeed be difficult to replicate in a simple way.
> 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
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.