fork download
  1. writeln = function(...)
  2. for i, v in pairs({ ... }) do
  3. if type(v) == "table" then
  4. local t = v
  5. if #v == 0 then
  6. t = {}
  7. for k, v in pairs(v) do
  8. table.insert(t, k .. ": " .. v)
  9. end
  10. end
  11. io.write("[ " .. table.concat(t, ", ") .. " ]")
  12. else
  13. io.write(v)
  14. end
  15. end
  16. io.write("\n")
  17. end
  18.  
  19. foo = function(...)
  20. print("Called foo ...")
  21. for i, arg in pairs({ ... }) do
  22. writeln(" args[", i, "] == ", arg)
  23. end
  24. print("... foo end")
  25. end
  26.  
  27. local tup = { 5, 3.14, "hello world", { 5, 10, 15 }, { foo = 5, bar = 10 } }
  28. foo(unpack(tup))
  29.  
Success #stdin #stdout 0.02s 2540KB
stdin
Standard input is empty
stdout
Called foo ...
    args[1] == 5
    args[2] == 3.14
    args[3] == hello world
    args[4] == [ 5, 10, 15 ]
    args[5] == [ bar: 10, foo: 5 ]
... foo end