[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: block-scope finalization
- From: Patrick Donnelly <batrick@...>
- Date: Tue, 24 Nov 2015 12:22:51 -0500
On Tue, Nov 24, 2015 at 11:52 AM, Roberto Ierusalimschy
<roberto@inf.puc-rio.br> wrote:
> What is wrong with the following proposal?
>
> local <some mark to be invented> name = exp
>
> Unlike a regular 'local' declaration, this one must define only one
> variable and it must be initialized. (Both restrictions could be easily
> removed; they are more about programming style.)
>
> When the local 'name' goes out of scope, then:
>
> 1 - if its value is a function, that function is called (no parameters)
> 2 - if its value is a table/userdata, its __close (or some other new
> name) metamethod, if present, is called.
>
> Otherwise, 'name' is like any other local variable.
+1! I think a new metamethod is required as an object may be opened
and closed repeatedly (like a mutex).
Open question: should __close be called after or before the "message
handler" for lua_pcall? I think after makes sense as the handler may
want to look at the open objects on the stack.
--
Patrick Donnelly
- References:
- Re: block-scope finalization, Viacheslav Usov
- Re: block-scope finalization, Philipp Janda
- Re: block-scope finalization, Viacheslav Usov
- Re: block-scope finalization, Philipp Janda
- Re: block-scope finalization, Philipp Janda
- Re: block-scope finalization, Viacheslav Usov
- Re: block-scope finalization, Coda Highland
- Re: block-scope finalization, Javier Guerra Giraldez
- Re: block-scope finalization, Coda Highland
- Re: block-scope finalization, Patrick Donnelly
- Re: block-scope finalization, Roberto Ierusalimschy