syntax.us Let the syntax do the talking
Blog Contact Posts Questions Tags Hire Me

Question:
In Lua how to pass variable args to function?

In Lua I can pass a variable number of args into a function using a table:
-- varargs.lua

-- I can pass a variable number of args into a function using a table.

function f1(tab1)
  return(tab1[7])
end

-- Also I can pass in named arguments.

atab = {name = 'Dan', rank = 'Major', sn = 1232}

function f2(tab2)
  return(tab2.name..tab2.rank..tab2.sn)
end

print(f2(atab))


syntax.us Let the syntax do the talking
Blog Contact Posts Questions Tags Hire Me