Сквозные параметры (in-out)

Функции

-- A number is copied: the caller's one stays
local function add_one(number)
  number = number + 1
  return number
end

local count = 5
local bigger = add_one(count)
-- count = 5
-- bigger = 6

-- A table is passed by reference: the function
-- changes the caller's table
local function swap_strings(t1, t2)
  t1[1], t2[1] = t2[1], t1[1]
end

local s1 = {"A"}
local s2 = {"B"}
swap_strings(s1, s2)
-- s1[1] = B
-- s2[1] = A

-- The parameter holds a copy of the reference:
-- a new table does not reach the caller
local function reset(list)
  list = {}
end

reset(s1)
-- s1[1] = B

print("count = " .. count)
print("bigger = " .. bigger)
print("s1[1] = " .. s1[1])
print("s2[1] = " .. s2[1])