This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

function with variable arguments
#1
I am currently trying to create a library for personal use to communicate in Modbus asci. I am trying to keep it as similar as possible to the luamodbus library built-in in the editor.
I wondered how the two write functions mb: write bits and mb: write registers have an indefinite number of arguments. 
While looking at the official Lua documentation, I found out I can use "..." as an argument in the function definition and then examine the arguments through the "arg" table. 

The problem is this seems not to be working while scripting on a Logic Machine which always gives back the same arg table.

Did I do something or wrong or maybe this is something that can not be used through normal scripting? Huh
Reply
#2
Like this:
Code:
function fn(...)
  local args = {...}
  
  for i, v in ipairs(args) do
    log(i, v)
  end
end

fn('a', 'b', 'c')
Reply


Forum Jump: