Passing A Table Of Arguments Into A Function Call

  1. What do you want to achieve?

I have a table of arguments that I do not know the amount or content that is in it, and I am trying to pass them into a function call.

  1. What solutions have you tried so far?

The problem with that is that table.concat turns the content into strings so I’m not passing the actual content I’m just passing them as strings, and also since the arguments could be of different types for example boolean, table.concat just errors.

Is this possible? if so how can I achieve this?

you can use ... in the function to get all the passed arguments

Yes, that’s to get the passed arguments in the function but that’s not the problem. the problem is that I am trying to pass these arguments to a function call that I have in a table. I am trying to find a way to split this arguments table by ‘,’ like table.concat without turning them into string so i can pass them into the function call.

Can’t you just pass a table to the function directly? I’m not understanding. What is the exact thing you’re trying to pass to the function? I can help from there.

I am trying to pass to the function a table of arguments. For Example.

local arg1 = "string"
local arg2 = 3
local arg3 = true
-- this is a example I do not know the amount of arguments or what they are

local argtable = {arg1,arg2,arg3}

-- somehow split argtable by ',' similar to table.concat without turning the
--elements into strings

local function method(table)
-- somehow returns arg1,arg2,arg3


Is this possible?

That doesn’t sound anything to me like table.concat but I might still be confused. I think you’re looking for unpack

local argtable = {"string", 3, true}
local arg1, arg2, arg3 = unpack(argtable)
print(arg2) --> 3
local function method(tab) -- Don't actually do this, just use unpack
    return unpack(tab)
local a, b, c = method(argtable)
print(c) --> true
1 Like

Use unpack like this

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.