[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Question about __index and classes
- From: Matthew Wild <mwild1@...>
- Date: Sat, 27 Aug 2011 19:06:37 -0400
On 27 August 2011 18:52, Michael Kirsch <firstname.lastname@example.org> 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,