lua-users home
lua-l archive

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


On Sat, Mar 22, 2014 at 1:34 PM, Andrew Starks <andrew.starks@trms.com> wrote:
>
>
> On Saturday, March 22, 2014, Roberto Ierusalimschy <roberto@inf.puc-rio.br>
> wrote:
>>
>> > >> There is no direct conversion from strings to integers:
>> > >> If a string is provided where an integer is needed,
>> > >> Lua converts the string to a float and then the float to an integer.
>> > Does it mean the following:
>> > assert('100000000000000001'%2 == 0)
>>
>> Yes.
>>
>>
>> > It looks unnaturally for a language having 64-bit integers as native
>> > datatype.
>>
>> Coercion from strings to numbers are considered a bad thing, and can
>> (should?) be removed in future versions. It did not seem worth to extend
>> to the new integer stuff something already outdate. (Ideally it should
>> raise an error, but that would create all sorts of incompatibilities.)
>>
>> In other words, it is unnatural, but the whole coercion stuff is
>> unnatural.
>>
>> -- Roberto
>>
>
> I'd like to suggest that the timing for changes to coercion is in this
> release.
>
> You introduced int 64 and language support for bits, plus changes to number
> formatting. 5.3 looks to be shaping up to be a "number" release. Eliminating
> string->number fits this.
>
> There are new operators, which makes this release especially significant,
> already. As is, I believe that these works have will prove to compel people
> to upgrade.  Even if someone agrees with the change in coercion, often a
> business case is needed, in order to do the hard work of checking for new
> bugs. Since I believe that you have that here, it may be good to take
> advantage.
>
> It's easier to take medicine when it's washed down with something you like
> eating.
>
> That's my perspective, anyway.
>
> Thank you for giving us this release!
>
>
>
> -Andrew

I actually wish there were a __tonumber metamethod and that the
underlying C for numbers and strings to coerce between them were
exposed through metatables.  So if you don't like coercion you could
turn it off with the debug library: debug.getmetatable(0).__tostring =
nil

I would expose more than that, sonny :ppp