[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Coercion to string does not call metamethod
- From: HyperHacker <hyperhacker@...>
- Date: Wed, 15 Jun 2011 15:00:25 -0600
On Tue, Jun 14, 2011 at 05:08, David Kastrup <firstname.lastname@example.org> wrote:
> Luiz Henrique de Figueiredo <email@example.com> 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.