String concatenation

Basic types / Strings

local s1 = "three"
local s2 = "two"

-- .. joins strings; no +=, assign the result back
local s3 = s1 .. ", " .. s2
s3 = s3 .. ", one"
local s_go = s3 .. ", go!"
-- s_go = three, two, one, go!

-- string.format builds it from one template
local formatted =
  string.format("%s, %s, one, go!", s1, s2)
-- formatted = three, two, one, go!

print("s_go = " .. s_go)
print("formatted = " .. formatted)

-- Only strings and numbers join
local missing
local ok, err = pcall(function()
  return "value: " .. missing
end)
-- ok = false
-- err = main.lua:21: attempt to concatenate a nil
-- value (upvalue 'missing')
print("ok = " .. tostring(ok))
print("err = " .. err)