lua-users home
lua-l archive

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

On Fri, Jun 24, 2016 at 6:45 PM, Javier Guerra Giraldez
<> wrote:
> (i'm quite rusty with pcall(), but i think the intention is clear...)
> of course, it would be a _lot_ better to avoid the function creation,
> and instead have some language support to hook resource release
> directly to scope exit:
>     do
>         local f = open(...)
>         onexit do f:close() end
>         .... do things with f ....
>     end
> and having the block in the onexit do .... end execute on any exit
> from the surrounding block.  of course, it should be possible to add
> several onexit do...end clauses.  a bit like go's 'defer' keyword
> (which is an example of non-RAII for a garbage-collected language,
> albeit an static one)

For other readers, this has also been extensively discussed in this
thread [1]. In particular, see Roberto's proposal [2].


Patrick Donnelly