lua-users home
lua-l archive

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


Hi All,

Looking at Lua-Reference for 5.2 section 3.4.2.
Coercion happens to numbers when used where a string is expected.
It is done the same way as tostring() would.

Why only to numbers and not to all other things, tostring() gives an answer for,
like specifically "nil", and "true"/"false"?

Timing it, I find that

   "text " .. x

with x a number is measurably faster than

   "text " .. tostring(x)

Having seen concatenation fail on nil or booleans, some people develop the
habit to tostring() everything, including numbers.

I think, the concatenation (and %s in format and ...)
should uniformly tostring() everything that is possible.

Thanks
Dirk