lua-users home
lua-l archive

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

I don't know, it seems like this behavior could be more helpful, like if you forgot to index an array to get a number out of it, silently returning nil isn't very helpful.

On May 29, 2011 2:56 PM, "Duncan Cross" <> wrote:
> It's my understanding that tonumber(), when called with a single
> parameter, is expected to return nil if it is given a non-numeric
> value, not to throw an error:
> print(tonumber('aaa')) --> nil
> print(tonumber({ })) --> nil
> print(tonumber(io.stdin)) --> nil
> However, it *does* throw an error if you give it an FFI cdata value
> which is non-numeric:
> print(tonumber( 'struct { }')) --> (!) cannot convert struct to double
> I believe this should be changed, to be consistent with the general case.
> -Duncan