[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: __goodies
- From: Roberto Ierusalimschy <roberto@...>
- Date: Thu, 3 Oct 2019 13:47:05 -0300
> A propos the Lua 5.40 (beta) manual I note that the __tostring
> event gets no mention in section 2.4 either. What other
> __goodies are being hidden from our eyes? Yes, I know, it is
> little hardship to scan the sources for them, but I did wonder
> if some very mild censorship was in play here :). Reveal all
> after beta, maybe?
__tostring is not part of the language itself, it is a peculiarity
of the function 'tostring'. The manual does have a note about that
at the end of Section 2.4:
Because metatables are regular tables, they can contain arbitrary
fields, not only the event names defined above. Some functions in
the standard library (e.g., tostring) use other fields in metatables
for their own purposes.
The reason for the absence of __close (and __gc, for that matter), is
because Section 2.4 concerns "certain special operations": Going
out of scope or becoming unreachable are not operations. We might
adapt the language to include __close and __gc there, but it is not
clear what would be the gains. (Should we include __mode too?)
For regular operations, metamethods work as extensions to the usual
semantics, so it makes sense to document them separately, to not
clutter the documentation of each operation.
On the other hand, __close is deeply attached to <close>. One is
meaningless without the other. So, it does not make much sense to
explain them separately. A similar argument seems to apply to __gc
and __mode. (However, "__name" is currently homeless.)
For a complete list of all indices used on metatables for all purposes,
the following shell script gives an answer:
$ grep -hoE '__[a-z]+' manual/manual.html | sort -u
-- Roberto