[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [ANN] Lua 5.3.0 (work2) now available (number coercion holy crusade)
- From: Andrew Starks <andrew.starks@...>
- Date: Tue, 25 Mar 2014 11:12:57 -0500
On Mon, Mar 24, 2014 at 11:41 PM, Tim Hill <drtimhill@gmail.com> wrote:
>> I don't agree. Lua should "not know what to do" so that a metamethod will be
>> looked for. Otherwise we can chuck away the __concat metamethod.
Yup. I get it now. Okay. Because we have concat as a metamethod,
calling tostring on concat. I'd rather have concat than automatic
tostring.
I think that what I was getting at is that I can see the case for
concat having a default metamethod that calls __tostring and if
__tostring is missing, there is error for non-strings. I don't have a
very strong position on this, however.
>
> I agree, and your example highlights the deeper difference between operator metamethods and coercion metamethods. I'd hate to see Lua ending up as messy as C++ where figuring out which function was called involves looking at templates, signatures, automatic casts etc etc .. (shudders).
>
> I think __tostring() should get invoked ONLY when tostring() is explicitly called.
I share your distaste for behavior A for in one context and behavior
B in another, but sometimes that's where the most useful things happen
and it can be wonderful, if it is done carefully. Example: print
always calling tostring.
That said, I'm a fan of things like "__to[every core type]" so my
opinion is from that world.
In my own _ENV, I have some of that, plus a "_type" metamethod and an
overloaded type library. It's the one hack that has stood the test of
time.
-Andrew
- References:
- [ANN] Lua 5.3.0 (work2) now available, Luiz Henrique de Figueiredo
- Re: [ANN] Lua 5.3.0 (work2) now available, Egor Skriptunoff
- Re: [ANN] Lua 5.3.0 (work2) now available, Roberto Ierusalimschy
- Re: [ANN] Lua 5.3.0 (work2) now available, Andrew Starks
- Re: [ANN] Lua 5.3.0 (work2) now available, Roberto Ierusalimschy
- Re: [ANN] Lua 5.3.0 (work2) now available (number coercion holy crusade), katlogic
- Re: [ANN] Lua 5.3.0 (work2) now available (number coercion holy crusade), Roberto Ierusalimschy
- Re: [ANN] Lua 5.3.0 (work2) now available (number coercion holy crusade), Hisham
- Re: [ANN] Lua 5.3.0 (work2) now available (number coercion holy crusade), Rena
- Re: [ANN] Lua 5.3.0 (work2) now available (number coercion holy crusade), William Ahern
- Re: [ANN] Lua 5.3.0 (work2) now available (number coercion holy crusade), Andrew Starks
- Re: [ANN] Lua 5.3.0 (work2) now available (number coercion holy crusade), Dirk Laurie
- Re: [ANN] Lua 5.3.0 (work2) now available (number coercion holy crusade), Tim Hill