[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Why can not using metatable to get meta-method?
- From: Xavier Wang <weasley.wx@...>
- Date: Sat, 6 Aug 2011 10:30:25 +0800
hi all,
We can get metamethod in a metatable:
local mt = { __newindex = function() print "here" end}
local t = setmetatable({}, mt)
t.abc --> here
but if here are no __newindex in mt, lua dont request the metatable of
the metatable:
local mmt = { __newindex = functoin() print "here" end}
mmt.__index = mmt
local mt = setmetatable({}, mmt)
print(mt.__newindex) --> a function
local t = setmetatable({}, mt)
t.abc --> nothing
it means that, you can not set a metatable to a metatable, to control
its behave.
Is that deliberate? Is there any reason to do that?