-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Varargs in functions #36
Comments
Unrelated side note, I love that github markdown syntax highlighting understands |
ZS supports the idea of varargs. Custom functions in ZS are still pretty limited. They do not allow for varargs. If you are looking on how to use varargs when in Java Code, you can see here Since varargs are just syntactic sugar for an array creation, you can create the array explicitly. zenClass MyClass {
zenConstructor(){}
function doSomething() as void {doSomething([]);}
function doSomething(arg0 as string) as void {doSomething([arg0]);}
function doSomething(arg0 as string, arg1 as string) as void {doSomething([arg0, arg1]);}
function doSomething(arg0 as string, arg1 as string, arg2 as string) as void {doSomething([arg0, arg1, arg2]);}
function doSomething(arg0 as string, arg1 as string, arg2 as string, arg3 as string) as void {doSomething([arg0, arg1, arg2, arg3]);}
function doSomething(varargs as string[]) as void{
/*Code here*/
}
} |
Looking at the CraftTweaker documentation for
IOreDictEntry
, the example for adding items indicates that varargs functions exist, as shown here:However, nowhere in the documentation for custom functions is there any indication of it being possible to declare a custom function to take a varargs parameter. I tried, as a quick test, declaring a function parameter
parameterName as string...
(and it was not just the last but the only parameter in that function) but running/ct syntax
gave me the error) expected
at that line. I also tried declaringparameterName... as string[]
and got the same error.Can custom functions be declared to take varargs parameters? If so, what is the syntax (and can it be added to the documentation)? If not, can this be implemented?
Final note: I felt this belonged in the ZenScript issue tracker because it's a feature inherent to the language, not the minecraft-specific application of it. If I'm wrong about that, I can open a copy of this on the CraftTweaker issue tracker instead.
The text was updated successfully, but these errors were encountered: