lua-users home
lua-l archive

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


On Aug 27, 2011, at 6:52 PM, Michael Kirsch 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. If
> so, then why is it necessary to say:
> 
>    MyClass.__index = MyClass
> 
> for you to be able to use ":"?
> 
> If ":" looks right in the metatable, then it shouldn't be needed. To
> me it seems like what it would do is let you call metamethods using
> the "." operator, but it doesn't work that way for some reason.
> 

That's not correct. o:f(p) is syntactic sugar for o.f(o,p) where p is 0 or more arguments. That's all.