-
-
Notifications
You must be signed in to change notification settings - Fork 416
Function overloading #7757
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
Function overloading #7757
Conversation
How? |
src/main/java/ch/njol/skript/lang/function/FunctionRegistry.java
Outdated
Show resolved
Hide resolved
I was thinking literal type clarification but I guess that's only for literals |
You could evaluate at runtime, which could be very flexible but also possibly confusing to users in some cases. |
|
I think I prefer a more limited system that errors at parse time over one that may cause runtime errors. Wdyt? |
|
Why not just use ExprValueWithin to clarify the type? |
Description
Adds function overloading.
Function overloading allows two functions with the same name to be registered, as long as
An example:
FunctionRegistry
Description
To accomplish this, a new
FunctionRegistryclass has been added, which is only visible to thefunctionpackage. This holds all signatures and functions by a namespace. A namespace is either the global namespace, for global functions, or a script, in which local functions can be registered.Functions and signatures are differentiated by a
FunctionIdentifier, which holds the function's name and the types of its arguments.Why are the methods in the Functions class not deprecated?
In the future, I plan on adding function parameter specification by name, e.g.
location(x=10,y=10,z=10,world="world"). When that has been added, there will, in my opinion, be enough future-proofing, thus the FunctionRegistry class can replace the Functions class' functionality. Overloaded functions will not be visible to Functions.Behaviour
When a function has an ambiguous type in one of its arguments, it will attempt to match based on the other arguments.
Therefore,
overloaded(1, {_none})andoverloaded({_none}, 2)will still call the correctoverloaded, as the functionoverloaded(int, int)is the only one that can be matched here.When a function has multiple implementations, and it can't be decided which one to use (due to variables for example), a parse-time error will be thrown.
Like other languages, functions cannot be differentiated by return type.
Target Minecraft Versions: any
Requirements: none
Related Issues: #1185, #2993