lua-users home
lua-l archive

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


On Tue, Jun 14, 2011 at 05:08, David Kastrup <dak@gnu.org> wrote:
> 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
>
>
>

Hmm, there is already __concat, but I see numbers don't use it, nor
have a default metatable at all (probably too slow). I'm not sure what
a "separate metamethod defaulting to tostring" would do?

-- 
Sent from my toaster.