lua-users home
lua-l archive

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


On Wed, Jul 13, 2016 at 3:33 PM, nobody <nobody+lua-list@afra-berlin.de> wrote:
> On 2016-07-13T10:11, Dirk Laurie wrote:
>> But it is not so easy if you have to worry all the time whether
>> 'str1 ~ str2' might not just decide to xor the bits instead of performing
>> whatever cute operation you have been using the syntax for. And if
>> you actually like the present behaviour, you can always supply
>> a metatable for that.
>
> Wouldn't it be enough if the auto-coercion (in any direction) happens
> _after_ checking for a metamethod? If that's reasonably easy to
> implement, that may be the way to go.
>
> For code not using metamethods on strings/numbers, nothing would change.
> (And I'd guess that code using metamethods on strings/numbers is more
> likely to be corrected by this than to be broken.)
>

Historically, the argument against this was that metamethods are
considered fallbacks -- things to be used when the default
implementation doesn't know what to do. This is partially a
performance question; it means that there can be a fast path for known
operations that doesn't require extra metatable lookups.

/s/ Adam