Skip to content

[Enhancement Request] Parsing of request to add function default arguments #48

Description

@ikexing-cn

Since CraftTweaker 4.1.20.668, ZenScript supports default arguments
This means that you can do:

function foo(a as int, b as int = 2, c as int = 3) as void {
    print(a + b + c);
}

foo(1); // print 6 [1 + 2 (default) + 3 (default)]
foo(1, 3); // print 7 [1 + 3 + 3 (default)]
foo(1, 1, 4); // print 6 [1 + 1 + 4]

Note 1: You can use bracket handlers and functions for default arguments. But variables are not allowed. Currently, they areseen as strings, but may produce parse exception in the future version.
Note 2: Once a parameter have a default argument, the parameters after it also require a default argument.

—— From friendlyhj

As yet, there is no corresponding syntax parsing for this function, and it is hoped that it will be added in the new version.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions