lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> I want to have a function that can be called with any number of 
> arguments(and I cant use a table because the function will be 
> called directly from C).
> It needs to be able to take it's arguments and pass them an an other 
> function like:
> 
> function wantargs(allmyargs)
> 	otehrfunction(allmyargs)
> end
> 
> and then I should be able to do:
> wantargs(1, 2)
> wantargs(1, 2, 3)
> wantargs("test")
> ...


Lua:

function takes_multiple_args(...)
  local arg_table = arg -- arg is a magic/automatic variable
  for i=1,getn(arg_table) do print(arg_table[i]) end -- print them out
end

takes_multiple_args()
takes_multiple_args(1,2,"buckle my shoe")
takes_multiple_args("three",4, {"heres", "some", "more"})
takes_multiple_args(6,"seven",8, "Lua is great")