lua-users home
lua-l archive

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


Hi,

I am wondering if this is possible. That is I want a
table which refers to another table if it doesn't have
the particular key and any write does not touch its
prototype. Initially, I thought it is easy

t1={a=1, b={}}
t2={}
setmetatable(t2,{__index = t1 })
t2.a => 1
t2.a = 2
t2.a => 2
t1.a => 1

So far so good. But
t1.b.a = 1
t2.b.a  => 1
t2.b.a = 2
t1.b.a  => 2 --this is not what I want

I then tried to loop through t1 and if it is of type
table, I create a new table and restart the COW
process. But running on _G would cause an endless
loop.

What I want to do is that I want to create an
environment for a function(setfenv) that sees the
callers environment but cannot modify it. It is not
the same as rings in cgilua which is completely
seperated from the caller's(well sort of).





 
____________________________________________________________________________________
Bored stiff? Loosen up... 
Download and play hundreds of games for free on Yahoo! Games.
http://games.yahoo.com/games/front