lua-users home
lua-l archive

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


On 19/04/2011 20:22, Roberto Ierusalimschy wrote:
I forgot about this one. There must be a reason for that, as it
seems as an unnecessary limitation? (I was just bitten by that in my
app).

It was caused by the use of strtou. (With strtol, we would have problems
with values greater than 2^31.) But in fact there is a bug there. If
the string is not a valid number, 'tonumber' should return nil. Unlike
some other functions, 'tonumber' should work with any argument.

So, tonumber("-0x10") should return nil ?

Just spotted another issue (could be a documentation issue): docs say that the default for `base' is 10, but in fact, if the first argument starts with 0x then the default is 16.

> =tonumber("0x10")
16
> =tonumber("0x10", 10)
16
> =tonumber("0x10", 16)
16
> =tonumber("0x10", 3)
nil

--
Shmuel