lua-users home
lua-l archive

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


> 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

PS - I've had pretty good results using boost::serialization to
serialize these Lua tables out to disk for game saving.  I do it
recursively, so you can put almost arbitrary stuff in these
environments, and they spring back to life on reloading.