lua-users home
lua-l archive

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


On Tue, Jan 12, 2010 at 11:00 AM, Juris Kalnins <juris@mt.lv> wrote:
> do ctx.a=1
>  do
>    local prev_a = ctx.a
>    ctx.a = 2
>    g(ctx)
>    ctx.a = prev_a
>  end
> end
>
>...
> When writing parser or GUI code, there is a lot of such 'ctx' passing and
> value saving.
> Dynamic scoping makes writing such code very natural.

True, but also less explicit.  It's easier to analyze explicit code,
like above we can see that exceptions will leave the environment
changed, etc.

It makes life more tricky (by making variable lookup more
complicated), for some convenience.

steve d.

PS. How about doing a _G + metatable + __index trick?  That could work.