-- No out parameters: the function fills
-- a table that the caller passes in
local function get_sum(out, n1, n2)
out[#out + 1] = n1 + n2
end
local ar_sum = {}
get_sum(ar_sum, 5, 3)
-- ar_sum = 8
-- Or the function returns several values
local function get_sum_diff(n1, n2)
return n1 + n2, n1 - n2
end
local total, diff = get_sum_diff(5, 3)
-- total = 8
-- diff = 2
print("ar_sum = " .. table.concat(ar_sum, ", "))
print("total = " .. total)
print("diff = " .. diff)