lua-users home
lua-l archive

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


On 3/16/06, David Morris-Oliveros <david.morrisoliveros@teambondi.com> wrote:
Now, to track both insertions and overwriting of existing entries in the
table, you have to use a proxy table (or something like it). Example:

tbl = {}
tbl.__proxy = {}
mt = {__index = function(t,k) return t.__proxy[k]; end,
      __newindex = function(t,k,v) print('tracked', k, v); t.__proxy[k]
= v; end}
setmetatable(tbl, mt)


This also breaks iteration of the table.  So these tables would need to be special cases, not good.  Ugh, I think I'll just add a __setindex metamethod so everything can work like normal.

--
// Chris