Concatenation


Concatenation refers to the common operation of joining of two strings. In Lua, when two strings are concatenated the result is a third string that contains the characters of the first string followed by the characters contained in the second string:

local x = "left side"
local y = "right side"

print(x .. y) -- left sideright side

-- separating strings with a literal " "
print(x .. " " .. y) -- left side right side

Note that the concatenation is literal: no space is added between two concatenated strings. When concatenating sentences be sure to include a literal space between the two strings.

Concatenation also works with numbers, by first coercing each value to its string-equivalent then concatenating those values:

local x = 2
local y = 3

print(x .. y) -- 23

Note that concatenation won't work with other value fundamentals, such as booleans or nil.