sourcepawn icon indicating copy to clipboard operation
sourcepawn copied to clipboard

[Feature request] Improve variadic argument support and increase effective variadic argument limit

Open Enovale opened this issue 7 months ago • 4 comments

Currently, SP_MAX_EXEC_PARAMS is set to 32, making it so that function calls cannot contain more than 32 parameters. This, importantly, makes it so that very large formatting class calls cannot be made without formatting multiple times in a row, which can be unacceptable in some cases (Such as using Sourcemod translations). Here's an example from a project of mine Showing how many formatting parameters I need and how I am being limited by the maximum parameters.

Additionally, there is currently absolutely no way to manipulate variadic parameters in any way other than using them in VFormat. You cannot grab individual entries in the parameter stack, nor can you pass along the entire stack to another method.

It is difficult to write clean-looking overloads for a method without being able to pass along variadic parameters. Additionally, a somewhat clean workaround for the first issue I described would be possible if I could iterate over the variadic parameters in chunks of <32 until the format is finished.

I can't say I know what the best solution for this codebase would be, but I would really like to see some improvements to variadic parameters. The most important being effectively increasing how many variadic parameters can be used. It would be even better if the parameters could be enumerated on an individual basis and reused in future method calls, even if it's a bit cumbersome.

The goal is to be able to format a very large formatting string (>32 parameters) using Sourcemod's translation system, and make code quality better with better access to the parameter stack.

Enovale avatar May 03 '25 09:05 Enovale

I think it's a good idea to support passing variable parameters. Variable parameters are only available for VFormat, which will significantly increase the complexity of the code in some cases.

F1F88 avatar May 15 '25 01:05 F1F88

I'm trying to think if this is doable without finishing the "rm-matchtag" branch. The syntax would be something like:

native any getarg(argpack, int arg_index);
native any getarg_array(argpack, int arg_index, any[] dest, int dest_len);
native any getarg_array_i(argpack, int arg_index, int array_index);
native void getarg_string(argpack, int arg_index, char[] dest, int dest_len);

void f(*args) {
    for (int i = 0; i < args.length; i++) {
        ...
    }
}

This is probably doable without the semantic rewrite, but I need to think about it.

dvander avatar May 29 '25 18:05 dvander

As to the pattern in the example: this is way beyond what the translation system was designed for, to be honest. I would break these into smaller phrases and then compose them.

dvander avatar May 29 '25 18:05 dvander

As to the pattern in the example: this is way beyond what the translation system was designed for, to be honest. I would break these into smaller phrases and then compose them.

Not really possible. The idea is to give the mod user the ability to make the phrase whatever they want. If there were just any way to use more than 32 params it would work fine.

Enovale avatar May 30 '25 05:05 Enovale