Skip to content

Commit 9bc7eec

Browse files
Merge pull request #18 from Instancify/refactor/functions
feat: new function executor and refactor: use new function executor for all functions
2 parents 7e38e40 + bffa98c commit 9bc7eec

File tree

90 files changed

+1461
-1266
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+1461
-1266
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ For adding a library only:
2121
<dependency>
2222
<groupId>com.instancify.scriptify</groupId>
2323
<artifactId>core</artifactId>
24-
<version>1.4.0-SNAPSHOT</version>
24+
<version>1.4.1-SNAPSHOT</version>
2525
</dependency>
2626
```
2727

@@ -30,12 +30,12 @@ For adding a library with JS for Rhino or GraalVM:
3030
<dependency>
3131
<groupId>com.instancify.scriptify</groupId>
3232
<artifactId>script-js-rhino</artifactId>
33-
<version>1.4.0-SNAPSHOT</version>
33+
<version>1.4.1-SNAPSHOT</version>
3434
</dependency>
3535
<dependency>
3636
<groupId>com.instancify.scriptify</groupId>
3737
<artifactId>script-js-graalvm</artifactId>
38-
<version>1.4.0-SNAPSHOT</version>
38+
<version>1.4.1-SNAPSHOT</version>
3939
</dependency>
4040
```
4141
## Gradle
@@ -49,11 +49,11 @@ maven {
4949

5050
For adding a library only:
5151
```groovy
52-
implementation "com.instancify.scriptify:core:1.4.0-SNAPSHOT"
52+
implementation "com.instancify.scriptify:core:1.4.1-SNAPSHOT"
5353
```
5454

5555
For adding a library with JS for Rhino or GraalVM:
5656
```groovy
57-
implementation "com.instancify.scriptify:script-js-rhino:1.4.0-SNAPSHOT"
58-
implementation "com.instancify.scriptify:script-js-graalvm:1.4.0-SNAPSHOT"
57+
implementation "com.instancify.scriptify:script-js-rhino:1.4.1-SNAPSHOT"
58+
implementation "com.instancify.scriptify:script-js-graalvm:1.4.1-SNAPSHOT"
5959
```

api/src/main/java/com/instancify/scriptify/api/exception/ScriptFunctionArgTypeException.java

Lines changed: 0 additions & 34 deletions
This file was deleted.

api/src/main/java/com/instancify/scriptify/api/exception/ScriptFunctionArgsCountException.java

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.instancify.scriptify.api.exception;
2+
3+
/**
4+
* Exception thrown when a function is called with
5+
* an incorrect number of arguments.
6+
*/
7+
public class ScriptFunctionArgumentCountMismatchException extends ScriptFunctionException {
8+
9+
/**
10+
* Creates a new exception for a mismatch in argument count.
11+
*
12+
* @param functionName The name of the function
13+
* @param expectedMin The minimum number of expected arguments
14+
* @param expectedMax The maximum number of expected arguments
15+
* @param provided The number of arguments actually provided
16+
*/
17+
public ScriptFunctionArgumentCountMismatchException(
18+
String functionName,
19+
int expectedMin,
20+
int expectedMax,
21+
int provided
22+
) {
23+
super("Function '" + functionName + "' expects between " +
24+
expectedMin + " and " + expectedMax + " arguments, but got " + provided);
25+
}
26+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.instancify.scriptify.api.exception;
2+
3+
/**
4+
* Exception thrown when a function is called with arguments
5+
* of incompatible types.
6+
*/
7+
public class ScriptFunctionArgumentTypeMismatchException extends ScriptFunctionException {
8+
9+
/**
10+
* Creates a new exception for an argument type mismatch.
11+
*
12+
* @param functionName The name of the function
13+
* @param index The index of the argument that failed validation
14+
* @param expected The expected type of the argument
15+
* @param actual The actual type of the provided argument
16+
*/
17+
public ScriptFunctionArgumentTypeMismatchException(
18+
String functionName,
19+
int index,
20+
Class<?> expected,
21+
Class<?> actual
22+
) {
23+
super("Function '" + functionName + "' argument #" + index +
24+
" expected type " + expected.getName() +
25+
" but got " + (actual == null ? "null" : actual.getName()));
26+
}
27+
}
28+

api/src/main/java/com/instancify/scriptify/api/script/constant/ScriptConstantManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.instancify.scriptify.api.script.constant;
22

33
import org.jetbrains.annotations.Nullable;
4+
import org.jetbrains.annotations.UnmodifiableView;
45

56
import java.util.Map;
67

@@ -14,7 +15,7 @@ public interface ScriptConstantManager {
1415
*
1516
* @return A map where keys are constant names and values are ScriptConstant instances
1617
*/
17-
Map<String, ScriptConstant> getConstants();
18+
@UnmodifiableView Map<String, ScriptConstant> getConstants();
1819

1920
/**
2021
* Gets a specific constant by its name.
Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
package com.instancify.scriptify.api.script.function;
22

3-
import com.instancify.scriptify.api.exception.ScriptFunctionException;
4-
import com.instancify.scriptify.api.script.Script;
5-
import com.instancify.scriptify.api.script.function.argument.ScriptFunctionArgument;
63
import org.jetbrains.annotations.NotNull;
7-
import org.jetbrains.annotations.Nullable;
84

95
/**
106
* Represents a function that can be used within scripts.
@@ -17,14 +13,4 @@ public interface ScriptFunction {
1713
* @return The function's name
1814
*/
1915
@NotNull String getName();
20-
21-
/**
22-
* Invokes the function with the provided arguments.
23-
*
24-
* @param script The script in which the function will be invoked
25-
* @param args The arguments to pass to the function
26-
* @return The result of the function execution
27-
* @throws ScriptFunctionException If there's an error during invocation
28-
*/
29-
@Nullable Object invoke(Script<?> script, ScriptFunctionArgument[] args) throws ScriptFunctionException;
3016
}

api/src/main/java/com/instancify/scriptify/api/script/function/ScriptFunctionManager.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.instancify.scriptify.api.script.function;
22

3+
import com.instancify.scriptify.api.script.function.definition.ScriptFunctionDefinition;
34
import org.jetbrains.annotations.Nullable;
5+
import org.jetbrains.annotations.UnmodifiableView;
46

57
import java.util.Map;
68

@@ -14,15 +16,15 @@ public interface ScriptFunctionManager {
1416
*
1517
* @return A map where keys are function names and values are ScriptFunction instances
1618
*/
17-
Map<String, ScriptFunction> getFunctions();
19+
@UnmodifiableView Map<String, ScriptFunctionDefinition> getFunctions();
1820

1921
/**
2022
* Gets a specific function by its name.
2123
*
2224
* @param name The name of the function to retrieve
2325
* @return The ScriptFunction associated with the name, or null if not found
2426
*/
25-
default @Nullable ScriptFunction getFunction(String name) {
27+
default @Nullable ScriptFunctionDefinition getFunction(String name) {
2628
return this.getFunctions().get(name);
2729
}
2830

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.instancify.scriptify.api.script.function.annotation;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
8+
@Retention(RetentionPolicy.RUNTIME)
9+
@Target(ElementType.PARAMETER)
10+
public @interface Argument {
11+
String name();
12+
13+
boolean required() default true;
14+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.instancify.scriptify.api.script.function.annotation;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
8+
@Retention(RetentionPolicy.RUNTIME)
9+
@Target(ElementType.METHOD)
10+
public @interface ExecuteAt {
11+
12+
}

0 commit comments

Comments
 (0)