lua-users home
lua-l archive

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


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

> > 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?
> Almost: changes should impact the caller too (hence, I set both
> __index and __newindex right now).
> 
> Basically, my C++ code maintains a bunch of separate Lua tables,
> one per game object.  When it's about to call a Lua fn for one of
> these, it sets up the module's metatable.  Then, any variables either
> referenced or created by the Lua functions being called go into
> the right table.  This is what i want, except that I also want it to
> follow the entire Lua call stack.
> 
> function a() 
>   some_var = true 
>   b()
>   print(some_var)
> end
> 
> function b()
>   print(some_var)
>   some_var = 5
> end
> 
> Should print true and 5, even if b is in another module somewhere.

CM, let me play devil's advocate here...

From my reading of what you wrote above, you basically want every
variable in every function to be, for want of a better word, a "public
variable." Is that REALLY what you want? That sounds a little dangerous to me.

SteveT