lua-users home
lua-l archive

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


Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br> writes:

>> So what is a core metamethod, and why is this one different?
>
> A core metamethod is one supported by the core. __tostring is something
> tostring offers and some other library functions use. It is not a core
> metamethod because it is defined by a library function.

Taking this statement into account, and returning to the original
concern mentioned in the subject title: should string coercion of a
number to string be subject to a core metamethod?

__tostring seemed like an obvious candidate.  However, a separate
metamethod defaulting to tostring (for a number) could be useful.  If
one wanted to disallow coercion, one could set the respective number
metamethod to nil, and one could make other types coerce to strings if
one wanted to.

-- 
David Kastrup