[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: state of the Lua nation on resource cleanup
- From: Asko Kauppi <askok@...>
- Date: Tue, 17 Feb 2009 19:30:32 +0200
Roberto Ierusalimschy kirjoitti 17.2.2009 kello 19:01:
What's wrong with Joonas Pihlaja's proposal?
do with f, g = io.open("src.txt","r"), io.open("dst.txt",w")
for l in f:lines() do
(Probably with a different syntax...)
I've been using it in metalua for a while (syntax "with <var_list> =
<values_list> do <scoped_statements> end") for some time, with the
convention that the protected variables must have a ":close()"
method, and I'm pretty happy with it.
I do not see why the need for the <scoped_statements>. It would be
simpler to add only a new form of locals. Something like
local finalized f, g = ...
that calls ":close()" (or __gc??) when it goes out of scope. Of
you can (should?) use a conventional do-end around it:
And all of that can easily be done using token modifiers.
Case solved? :)
(this must be the longest surviving thread in lua-list history)
do local finalized f, g = ...
But the do-end is not part of the syntax.