lua function and undefined number of argument ?

Place to get help with not working mods / modding interface.
User avatar
binbinhfr
Smart Inserter
Smart Inserter
Posts: 1525
Joined: Sat Feb 27, 2016 7:37 pm
Contact:

lua function and undefined number of argument ?

Post 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...
My mods on the Factorio Mod Portal :geek:
User avatar
binbinhfr
Smart Inserter
Smart Inserter
Posts: 1525
Joined: Sat Feb 27, 2016 7:37 pm
Contact:

Re: lua function and undefined number of argument ?

Post 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
My mods on the Factorio Mod Portal :geek:
Post Reply

Return to “Modding help”