lua-users home
lua-l archive

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


On Sat, 24 Mar 2012 15:56:17 -0700 (PDT)
codemonkey Monkey <thecodemonkey@rocketmail.com> wrote:

> Hi Steve!  Thanks for your reply.
> 
> > If there's no such thing, what's wrong with every subroutine making
> > a
> call to a quick program to retrieve the intended environment?
> 
> Well, a few things.  The major one is that you have to do it each and
> every time, or it's a bug.  I had essentially that when I was calling
> "setfenv" in every Lua function.  First it litters up every Lua fn
> with extra lines of code, but more importantly it's fragile against
> programmer errors. I was constantly forgetting to do it, and then I
> had subtle defects in my Lua code where some variable that should
> have gone to the environment-of-interest really went elsewhere.
> Since there's no compile-time checking in Lua (already dangerous
> itself), that's a pretty dangerous situation.

OK, now I understand your situation, so forget my stack of environments
object idea. And I don't think my idea would have worked anyway,
because in Lua tables are passed/assigned by reference, so changes at
level 7 would affect level 6, which is not what you want.

So if I understand you correctly, you want to be able to look at
variables and have them be the value they were in the caller, but
change them without affecting the caller. Do I have it right so far?

Thanks

SteveT