From the Lua 5.3 doc:
__index
: The indexing accesstable[key]
. ... The metamethod is looked up intable
.
It says the same thing for __newindex
, but not for any other metamethod.
If this were true (which it's not), it would be a major departure from previous versions of Lua. The following code outputs nil
, as I would expect, but it's inconsistent with the doc.
#!/usr/bin/env lua5.3
local proto = {a = 54}
local t0 = {__index = proto}
print(t0.a)
To be clear: If the doc was correct, I would expect t0
in the above code to only require an __index
field without an actual metatable for t0.a
to be 54
. So does anyone know what's going on with the doc?