lua-users home
lua-l archive

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

On Mon, Mar 24, 2014 at 11:41 PM, Tim Hill <> 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

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