lua-users home
lua-l archive

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


On Tue, 12 Jan 2010, steve donovan wrote:
> On Tue, Jan 12, 2010 at 2:07 PM, Tony Finch <dot@dotat.at> wrote:
> > If there were hooks on the environment of 5.2 "in" blocks so that the code
> > knows when the block is finished, you could perhaps write something like
> >
> > do a=1
> >  in dynamic{ a=2 } do
> >    g() -- access to a gives 2
> >  end
> >  -- a == 1
> > end
>
> Yes, assuming that g is local, of course.

What I had in mind was that dynamic(t) copies t into _G and returns _G,
then when the in/do/end block finishes it restores _G to its former state.

> Having a lexical-block-finished hook would be a powerful tool indeed,
> for RAII-style cleanup etc.

Indeed :-)

Tony.
-- 
f.anthony.n.finch  <dot@dotat.at>  http://dotat.at/
GERMAN BIGHT HUMBER: SOUTHWEST 5 TO 7. MODERATE OR ROUGH. SQUALLY SHOWERS.
MODERATE OR GOOD.