[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Coercion in concatenation.
- From: Dirk Zoller <duz@...>
- Date: Mon, 25 Aug 2014 07:51:14 +0200
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