Hello, I would like to know if this is correct or how I can use multiple arguments in a function, could you give me an example or how to correct the one I already did?
local function do_something (...)
local c = ...
end
do_something(print("dsdsd", "dsdsds", true, "safsadf"))
If you want to split the arguments into different variables, you can use local a, b, c = ... for one instance. Otherwise you can contain it in a table.
local function using_table (...)
local args = {...}
end
local function using_var (...)
local var = ...
end
using_table("text1", true, "text2")
print(using_table)
using_var("text", true, "text2")
print(using_var)
local function get_varargs_table(...)
return {...} -- returns a table with the arguments passed
end
local function get_varargs_raw(...)
return ... -- returns all of the arguments that were passed (without a table)
end
print(get_varargs_table("this", "is", "a string", "+", 0))
print(get_varargs_raw("this will print", "all of these arguments"))
Oh, I was under the impression that you were using this in studio. It prints the table’s memory address because that’s how it functions in normal lua. You could do this though:
local function get_varargs_table(...)
return '{ ' .. table.concat({...}, ', ') .. ' }'
end