I can't figure out how to iterate through parameters. Usually I would use the
1 | for i,blank in pairs (table) do |
2 | print ( "One of the elements of this table is: " .. blank) |
3 | end |
But I don't know how to put the parameters in instead. I'm also open to other functions or any others ways to do it.
There's multiple ways you could go about this, but the easiest solution is to use ...
as your parameter instead. This will let you iterate through a table in the scope of the function.
An example
01 | function printAll(...) |
02 | local arg = { ... } |
03 |
04 | for i, blank in pairs (arg) do |
05 | print ( "One of the elements of this table is: " .. blank) |
06 | end |
07 | end |
08 |
09 | printAll( 5 , 9 , 8 ) |
10 | printAll( "hello" , nil , "world" ) |