lua-users home
lua-l archive

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


On 27 August 2011 18:52, Michael Kirsch <mkirsch358@gmail.com> wrote:
> There is something I don't understand about the way __index and
> metamethods work. The way I understand, the "." operator looks in the
> table itself and the ":" operator looks directly in the metatable.

This understanding is wrong. There is no difference in how '.' and ':'
index the table.

The only difference is that ':' automatically passes the table on its
left as the first parameter to the function being called.

foo.bar(foo, 1, 2, 3)
foo:bar(1, 2, 3)

are exactly the same, having nothing to do with metatables.

Hope this helps,
Matthew