[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [manual] chaining metamethods
- From: Coda Highland <chighland@...>
- Date: Wed, 27 Jan 2016 10:35:24 -0800
On Wed, Jan 27, 2016 at 10:27 AM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
> 2016-01-27 19:04 GMT+02:00 Stephan Hennig <sh-list@posteo.net>:
>
>> Note that queries for metamethods are always raw; when
>> looking-up metamethods, Lua doesn't consider a metatable's
>> metatable. Lua considers metatables of metamethods, though.
>> In fact, chaining metamethods is at the heart of many
>> approaches to object-oriented programming in Lua.
>
> Sorry, I find this more obscure than the original one-sentence
> description.
>
>> Note that queries for metamethods are always raw; the access
>> to a metamethod does not invoke other metamethods.
>
> I read this as "if the metatable does not contain for example
> __add, the __index metamethod is not invoked to find
> a fallback, eic." What other way is there of reading it?
>
It could also be read (erroneously) as "y = x.__add will always be
raw". At the very least it could be said that built-in operations will
always look up metamethods using raw access or something like that.
/s/ Adam