Allow Selection:Set() to accept variadic arguments

So lets say I have three variables, a, b and c, and I want to select them directly.

local a = Instance.new("Part",workspace)
local b = Instance.new("WedgePart",workspace)
local c = Instance.new("TrussPart",workspace)

Right now, we have to do something like:

game.Selection:Set({a,b,c})

or

game.Selection:Set{a,b,c}

Wouldn’t it be nicer if we could just do this?

game.Selection:Set(a,b,c)
1 Like

No. Use existing syntax. If we added a different variant of syntax every time someone wanted to make trivial changes like this, the API would be 100 times the size of what it is now. Not to mention having optional varargs in one method would break consistency with others that are still restricted to a table. If you really don’t like how it’s set up now, use a wrapper. Alternatively, if you don’t like the double brackets/parentheses, you can just do game.Selection:Set{a,b,c}.

I haven’t looked into this at all but the implementation is actually quite tricky, we would need to add support for variadic args in reflection. It is probably not worth it to do this without a compelling use case.

@EchoReaper is also right in saying that this leads to API bloat and that is enough of a reason not to do this in itself.

2 Likes

I agree this isn’t worth the syntax change.

For future reference you can accept variadic args without modifying reflection by binding directly to the Lua API from C++ (see WaitForChild’s implementation). However, besides several other drawbacks, this is risky as the changes cannot be flagged.

2 Likes

I actually found this type of reflected function after taking a look earlier today but I didn’t immediately realize that it could be used for variadic args (obvious in hindsight, you can just use lua_gettop()). Anyway, still not really worth doing.

Also, this can be flagged by the way, ReadVoxels uses this and it is flagged based on whether smooth terrain is enabled.

1 Like

Yeah, but you can’t flag reflection changes of this nature if you’re switching from arguments into direct binding, as reflection is done at compile time.

And yeah, not worth.

Ah yes, you’re right, I misunderstood what you meant.

1 Like