Page 1 of 1

lua function and undefined number of argument ?

Posted: Sun Apr 24, 2016 4:14 pm
by binbinhfr
Hi,

I just wonder if the LUA used by factorio supports function with undefined number of arguments like in this référence (réf : https://www.lua.org/pil/5.2.html)

Code: Select all

    printResult = ""
    
    function print (...)
      for i,v in ipairs(arg) do
        printResult = printResult .. tostring(v) .. "\t"
      end
      printResult = printResult .. "\n"
    end
Because it does not seem to work with me ("attempt to call a nil value"), so I wonder if I miss something or...

Re: lua function and undefined number of argument ?

Posted: Sun Apr 24, 2016 4:34 pm
by binbinhfr
well I found the answer by myself :-)

if someone interested, the "arg" syntax is outdated : the new syntax for this is :

Code: Select all

    printResult = ""
   
    function print (...)
      for i,v in ipairs({...}) do
        printResult = printResult .. tostring(v) .. "\t"
      end
      printResult = printResult .. "\n"
    end