Variadic Functions

Jul 1, 2023  │  m. Jul 2, 2023 by Gleb Buzin

Variadic Function receive unknown number of parameters

function getSum(...)
    local sum = 0

    for k, v in pairs{...} do
        sum = sum + v
    end
    return sum
end

io.write("Sum : ", getSum(1,2,3,4,5,6), "\n")
Sum : 21


Next: Variable Scope