[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: Dirk Laurie <dirk.laurie@...>
- Date: Mon, 24 Mar 2014 07:01:33 +0200
2014-03-23 23:32 GMT+02:00 <katlogic@katsystems.eu>:
> On Sun, Mar 23, 2014 at 04:40:24PM -0300, Roberto Ierusalimschy wrote:
>> > I'd like to suggest that the timing for changes to coercion is in this
>> I am afraid elimination of this conversion is a much deeper disruption
>> than it seems; I would love to be proved wrong.
>
> Most common breakage seem to be (%d+) captures. This is reasonably
> possible to work around for legacy code by wrapping string.* to
> catch (%d+) in patterns and call tonumber() for given result position.
Breakages that would give an error message are relatively easy
to handle.
For my applications, the following halfway stage would be sufficient:
when _both_ operands in an arithmetic expression (including, now,
bitwise operations) are strings, check for the presence of the
appropriate metamethod _before_ trying coercion and performing
the operation on numbers.
E.g.
$ lua53
Lua 5.3.0 (work2) Copyright (C) 1994-2014 Lua.org, PUC-Rio
> 1+2 -- so that you can see the difference later
3
> "1"+"2" -- coercion goes to float!
3.0
> getmetatable"".__add = function(x,y) return x..'+'..y end
> "a"+"b"
a+b
> "1"+2 -- for this case, I can live with coercion
3.0
> "1"+"2" -- but here I want the result "1+2"
3.0
Would this still be very disruptive?