[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: "nesting" metatables
- From: Philipp Janda <siffiejoe@...>
- Date: Thu, 31 Dec 2015 13:14:05 +0100
Am 31.12.2015 um 12:41 schröbte Dirk Laurie:
2015-12-31 10:34 GMT+02:00 Marc Balmer <marc@msys.ch>:
When a nested __index metamethod is being called, does
it still get the original table as the first argument, or the table
that caused this __index metamethod to be called (i.e. the
previously indexed table)?
It's a dozen lines of Lua code to figure this out, and it would have
prevented a lot of confusion:
local mt = {
__index = setmetatable( {}, {
__index = function( o, k )
print( o, k )
end
} )
}
local t = setmetatable( {}, mt )
print( "t", t )
print( "mt.__index", mt.__index )
local dummy = t.x
Typical output:
t table: 0x1d16060
mt.__index table: 0x1d16530
table: 0x1d16530 x
It's a tail call. I.e. all that happens is that exactly the same
stack is presented to the new function. Since the original
table was the first argument, it still is.
If I understand the question correctly, this is wrong. See above.
Philipp