lua-users home
lua-l archive

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


I find that the reference manual for Lua 5.1 is disturbingly vague on the matter of converting numbers to strings and strings to numbers. Pretty much all it says is in section 2.2.1, string to number is done "following the usual conversion rules", and number to string is done "in a reasonable format".

I realise that the Lua team cannot reasonably make it absolutely precise, because even if luaconf.h has not been modified by the user, the underlying operations depend on the C library. But I feel that some more could be said, for example:

Reasonable sized integers will be converted to a string that does not include a decimal point.

When converting strings to numbers, preceding and trailing whitespace is stripped.

When converting strings to numbers, an optional minus sign is acceptable.

Both hexadecimal and decimal (floating point) conversions are possible.

I feel that they would be useful additions to the manual.

By the way, I was surprised by the result of

return '-0x1' + 0

I was even more surprised when it gave a different answer on my PowerPC OS X machine (where it gives -1) than on an Intel Windows XP machine (where it gives 4294967295).

David Jones