A way to use tuples independently?

Is there a way I can use tuples independently, such as how you would do it in python, (arg_1, arg_2)? I tried using this method but it just returns an error, so if you have any idea if this is even possible I’d like to hear your feedback.

Can you show us Roblox Lua implementation you tried?

I’m a bit confused, you can just do in the parameters (…) which allows you to have as many arguments.

I tried indexing the tuple like a table, example: (arg1, arg2)[1].

You will need to use a table. They are flexible in Lua, don’t hesitate to use them.

I was hoping that I could use a tuple, since I want it to be a distinguishing factor amongst the tables which it is used with.

Use a Table, and then use unpack() function.

I tried that but the tuple is inside a table, so arguments are passed into the table without any corralation.

What about using table.pack(arg1, arg2)[1], it should work too

That just packs it into a table.

You can’t use “tuples” independently because Lua doesn’t have “tuples” in the first place. They’re not packed into a single data structure. They’re (IIRC) multiple values that’s stored in the stack. If Lua returns multiple value, they really return multiple value.

You can use (select(index, ...)) to index multiple values if that’s what you’re looking for.

What’s wrong packing them into tables?

1 Like

The reason I don’t want to pack them into a table is because I want there to be a distinguishing factor, which I can use the function type() with. I’m working on a module and I want it to be as compact as possible. I pretty much got my answer though, thanks.

you can do something like

function myFunc(player,data,...)
   local args = {...}
   local args[1] = "changes"
   --now ready to pass to another function with varangs
1 Like

This was exactly what I needed. Thanks! It allows me to convert a table into a list of parameters which are on the stack for a function call, and to support the use case where that list is “tuple-like” with a variable number of parameters.

1 Like