Casting#
Lua does few implicit conversions and many explicit ones.
From / to |
How |
|---|---|
any to string |
|
string to number |
|
string in base N |
|
number to integer (truncate) |
|
number to integer (ceil) |
|
to clean boolean |
|
Arithmetic between a number and a string that looks like a
number works in 5.1 / 5.2 / 5.3 but raises in 5.4. The operator
does not rely on this; use tonumber first.
print("3" + 1) -- 4 in 5.3, error in 5.4
print(tonumber("3") + 1) -- 4, portable