lua-users home
lua-l archive

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


2011/8/6 Brian Maher <brian@brimworks.com>:
> I think you want the __index to be set on the mt, not the mmt.  For
> example, this works fine:
>
> local mmt = { __newindex = function() print "here" end}
> local mt = setmetatable({}, mmt)
> mt.__index = mt
> local t = setmetatable({}, mt)
> t.abc = "abc"
I have tried this, and get confusion with it: the "here" print is on
the line "mt.__index = mt", this is a "newindex" operation, not on the
line "t.abc = "abc"".


>
> Alternatively, you could copy over the __newindex function like this:
>
> local mmt = { __newindex = function() print "here" end}
> local mt  = setmetatable({}, mmt)
> mt.__newindex = mmt.__newindex
> local t   = setmetatable({}, mt)
> t.abc = "abc"
this is good method, thank you :)

>
> Cheers,
> -Brian