lua-users home
lua-l archive

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


On Tue, Jul 26, 2011 at 02:46, Dirk Feytons <dirk.feytons@gmail.com> wrote:
> Hi list,
>
> I noticed some inconsistent behavior in tonumber(), both in Lua 5.1
> and the current 5.2 beta:
> tonumber({}) returns nil
> tonumber({}, 16) throws an error
>
> Is there a specific reason why the behavior is different when a
> non-default base is given?
>
>
> --
> Dirk
>
>

Hmm, this is also interesting:
> n=99
> print(tonumber(n,16))
prints 153 (which is 0x99). It seems when you specify a base, it
converts the value to a string and then interprets it as a number,
even if it were already a number to begin with.

I feel like tonumber() should just return the number it's given if it
is in fact a number (no conversion is necessary), but I'm not sure
what it should do about the base in that case.

-- 
Sent from my toaster.