[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: RE: How can I hook into gc?
- From: "Nick Trout" <nick@...>
- Date: Wed, 19 Nov 2003 22:17:51 -0800
> I guess i was just thinking it would be nice if you could decide for
> yourself if you wanted to allow pre-existing values to be returned or
> able to override the value returned at times. No big deal...
I sometimes wonder why Lua doesn't have __get and __set which are called
every time, rather than the current system.
> I don't see how I can do that with __index or __newindex... looks like
> they would both just silently assign nil and not inform me. I tried a
> couple permutations but couldn't get it to go.
> Any chance you have the time to give an example? S'ok if you don't -
> we're all busy folks. :)
You need to use an empty proxy table. The table you set the metamethods
on is empty. The values that you store in the this table are actually
stored elsewhere in another table. That way __index and __newindex get
called every time.