[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: state of the Lua nation on resource cleanup
- From: Sam Roberts <vieuxtech@...>
- Date: Sat, 14 Feb 2009 14:34:35 -0800
On Sat, Feb 14, 2009 at 2:02 PM, Farmbuyer <farmbuyer@gmail.com> wrote:
> On Sat, Feb 14, 2009 at 12:39 PM, Sam Roberts <vieuxtech@gmail.com> wrote:
>> On Fri, Feb 13, 2009 at 6:18 AM, Roberto Ierusalimschy
>> <roberto@inf.puc-rio.br> wrote:
>> Would it be easier for people to implement finalization if tables
>> supported the __gc metamethod?
>>
>> I'm thinking I could do something like:
>>
>> function f()
>> local io
>> local _ = setmetatable({}, {
>> __gc = function() io:close() end
>> })
>> io = io.open()
>> ...
>> return
>> end
>
> It seems vaguely like misuse of tables; nothing's being stored,
Hm, well, lua uses tables for pretty much everything ;-)
> nothing's being hashed, a table is being created when all we really
> need is the metamethod. (I realize it's just an example.) I think
> I'd prefer using newproxy.
True, except newproxy() is undocumented, and described by the authors as a hack.
As far as I can tell, newproxy() exists as a work-around because
tables don't have __gc.
Sam