[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: nested __index
- From: "temp 213 qwe" <temp213@...>
- Date: Fri, 25 Aug 2023 22:58:40 +0600
__index:
"If it is a function, it is called with table and key as
arguments, and the result of the call (adjusted to one value)
is the result of the operation. This indexing is regular, not
raw, and therefore can trigger another __index metavalue."
a = setmetatable({a = 1, name = "a"}, {__index = function(t,
k) print(t.name) end})
b = setmetatable({b = 2, name = "b"}, {__index = a})
print(b.a, b.b, b.c)
I understand why it prints "a" table name, when indexing b.c,
but should not it be more correct to propagate "b" to all the
nested __indexing?
"child" table could store a link to "parent" (in __index
actually), but if at the end of nested __indexing process we
got last "parent" as self, there is no way to get a child who
actually triggered it, or?
best regards,
Pavel