lua-users home
lua-l archive

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


2015-01-04 12:21 GMT+02:00 Lorenzo Donati <lorenzodonatibz@tiscali.it>:

>  A detailed list of events controlled by metatables is given next. Each
> operation is identified by its corresponding **event name**. The **key
> for each event** is a string with **its name prefixed by two
> underscores, '__'**; for instance, the key for operation "add" is the
> string "__add". Note that queries for metamethods are always raw; the
> access to a metamethod does not invoke other metamethods. You can
> emulate how Lua queries a metamethod for an object obj with the
> following code:
>
>      rawget(getmetatable(obj) or {}, event_name)
>
> in this latter Lua code line the 2nd argument apparently refers to the
> /name/ of the event, but it should refer to the associated /key/.
> It could seem nitpicking, but the cited paragraph is very precise and
> seem to stress the difference quite a bit. Therefore that 2nd argument
> could confound the newbie reader, especially if he has paid due
> attention to the previous lines.

Anyone trying to query or redefine metamethods is by definition
not a newbie :-)

The way I read the passage in the original, unhighlighted version
is that e.g. "add" is the name of the metamethod, as used in the
immediately following description list, and "__add" is its event name,
which is also the key used for indexing in the metatable. I do not
find that confusing.

But trying to understand why a third term is introduced when two
are enough would be confusing to me.