-
-
Notifications
You must be signed in to change notification settings - Fork 404
Function package rework and named function arguments #8112
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
Open
Efnilite
wants to merge
56
commits into
dev/feature
Choose a base branch
from
feature/named-function-args
base: dev/feature
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This was
linked to
issues
Aug 4, 2025
Absolutionism
requested changes
Aug 5, 2025
src/main/java/org/skriptlang/skript/lang/function/FunctionArgumentParser.java
Outdated
Show resolved
Hide resolved
src/main/java/org/skriptlang/skript/lang/function/FunctionReference.java
Outdated
Show resolved
Hide resolved
src/main/java/org/skriptlang/skript/lang/function/ScriptParameter.java
Outdated
Show resolved
Hide resolved
src/test/java/org/skriptlang/skript/lang/function/FunctionArgumentParserTest.java
Outdated
Show resolved
Hide resolved
src/main/java/org/skriptlang/skript/lang/function/FunctionArguments.java
Outdated
Show resolved
Hide resolved
src/main/java/org/skriptlang/skript/lang/function/FunctionReference.java
Outdated
Show resolved
Hide resolved
src/main/java/org/skriptlang/skript/lang/function/FunctionReference.java
Outdated
Show resolved
Hide resolved
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
breaking changes
Pull or feature requests that contain breaking changes (API, syntax, etc.)
bug
An issue that needs to be fixed. Alternatively, a PR fixing an issue.
feature
Pull request adding a new feature.
functions
Related to functions
needs reviews
A PR that needs additional reviews
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Skript should add named function arguments, similar to languages like Kotlin. This increases the clarity of which argument is passed.
Example:
Also, the function package code is a mess.
Solution
Named function arguments
Named function arguments act as you would expect. They are always usable, except for when mixing named and unnamed arguments. To avoid assigning the incorrect value to a parameter, mixing named/unnamed is only allowed when the named arguments are in the same order as the parameters of the function. An example.
Lists are also supported.
Rework changes
Function references
Function references have had a major rework. These changes are extensive and happen predominantly in
SkriptParser.
To try and improve organization, all function parsing code has been moved to theFunctionParser
subclass. To accommodate these changes ,njol.FunctionReference
has been deprecated and has been replaced byskript.FunctionReference
.Function references are now determined inside the parser by using existing function signatures, which allows it to automatically select the correct function reference based on the argument types (fixing #8106). For every signature, it will attempt to parse the given arguments to the types belonging to the signature. If this is successful, it will continue with all other signatures. Then, if only one signature is valid, an exact match has been found. If there are multiple matches, an error will be printed.
The integration with
SkriptParser
also removes the need to fetch the signature of functions at runtime, as these can be stored directly inside the reference, which improves performance and reduces complexity.Function arguments
Since Skript doesn't support the format to achieve named function arguments, a new function reference argument parser has been written. On receiving the input string, this parser correctly separates the arguments into arguments, and also determines whether these arguments are named or not. An example output is as follows.
Function execution
Since position is no longer relevant, all function execution is now handled via the abstract
Function#execute(FunctionEvent, FunctionArguments)
method. Instead of a 2D object array, functions now have access toFunctionArguments
, which is essentially a glorified map. This map holds all the passed function arguments by name. The old execution method has been deprecated.Parameters
njol.Parameter
has been deprecated and has been replaced by the following classes, both of which implement the newskript.Parameter
interface.skript.ScriptParameter
: for parameters that are parsed from scripts. This class has an additional default value attribute, as well as the attributes provided byskript.Parameter
. This default value is used in e.g.x: int = 3
;skript.DefaultParameter
: for parameters forDefaultFunction
s. This class has no additional attributes other than those provided byskript.Parameter
;These new parameters use classes instead of classinfos for their types. When a parameter accepts multiple values, its type is e.g.
Integer[]
orString[]
. When it accepts a single value, it is e.g.Integer
orString
. Parameters also have a set of modifiers, which dictate the behaviour of the parameter. TheModifier
interface details the two currently used parameters:OPTIONAL
: for function parameters that are optional,KEYED
: for function parameters that accept keyed values.Furthermore, parameters are now stored as a
LinkedHashMap
, which encourages the intended use for accessing function arguments. Using names and accessing the first argument are easy, while getting a parameter by its position is now more involved. Due to Skript still supporting Java 17,SequencedMap
cannot be used as an abstraction ofLinkedHashMap
yet.Parameter parsing
Script parameter parsing has been relocated from the (soon-to-be-extinct)
Functions
class. Parsing a single parameter has been moved toScriptParameter
, and parsing the entire signature of a script function has been moved to the new subclassStructFunction.FunctionParser
.Adds -> as a function return prefix
Looks nicer than the others :)
Testing Completed
Supporting Information
Breaking changes
SkriptParser#parseFunction(Class[])
has been entirely replaced withSkriptParser#parseFunctionReference()
Function#execute(FunctionEvent, FunctionArguments)
must be implemented by anyone extendingFunction
directlySignature#getParameters()
andSignature#getParameter(int)
have had their return type changed toskript.Parameter
instead ofnjol.Parameter
ExprFunctionCall
andEffFunctionCall
's constructors have changed from acceptingnjol.FunctionReference
to now acceptingskript.FunctionReference
.JavaFunction#execute
, the implementation oflocation
has been updated to avoid the world being null. (as described in Java function rework #7969)njol.Parameter
andnjol.Signature
have been changed to be private, with methods being added for access.ScriptFunction#setReturnValue
(deprecated since 2.9)SkriptParser#wildcard
(deprecated since 2.8)SkriptParser#listSplitPattern
(deprecated since 2.7)Completes: #7987, #8106
Related: none