lua-users home
lua-l archive

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

On 17/01/2015 00:04, Coda Highland wrote:
On Fri, Jan 16, 2015 at 2:29 PM, Lorenzo Donati
<> wrote:

On 16/01/2015 22:38, Roberto Ierusalimschy wrote:

Is there a reason why the coercion first recognizes the string as
representing an int and then "throws away" that info and converts it
unconditionally into a float?

We want a fast track for integers, so the first check is simply whether
both operands are integers. After that check, it is too cumbersome to
recheck whether the strings are "integers" and then also do an integer

-- Roberto

Thanks for the clarification!

I'm not really sure, maybe I just must get used to it, but the whole
string->number automatic coercion thing seems to have become a bit
overcomplicated. I only relied a few times on this behavior before (pre
5.3), so I wouldn't miss it should you remove it from the language and raise
an error whenever a string is used where a number is expected. As it stands
now the feature seems to me a bit counterintuitive or at least too
convoluted and perhaps can cause more harm than good. Just a gut feeling,
though. (my 2c)


-- Lorenzo

Isn't there a #define you can set now to disable string-to-number coercions?

Really? I didn't know that. Thanks for the tip!

I'd like not to use that, since I use Lua essentially as an external script interpreter and not embedded in C applications, so I prefer to stick with the defaults settings to lessen "compatibility" problems.

Probably I should grow the habit of using "tonumber" more often, which BTW is also good programming practice.

/s/ Adam