Skip to content

Commit c51c913

Browse files
committed
chore: added README
1 parent f02681d commit c51c913

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed

README.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Scriptify Kotlin Script
2+
This library adds Kotlin Script implementation for the [Scriptify](https://github.com/Instancify/Scriptify) library.
3+
4+
## Example of usage
5+
Kotlin example
6+
```kotlin
7+
import com.instancify.scriptify.common.script.constant.CommonConstantManager
8+
import com.instancify.scriptify.common.script.function.CommonFunctionManager
9+
import kotlin.script.experimental.api.ResultValue
10+
11+
fun main() {
12+
val script = KtsScript()
13+
script.functionManager = CommonFunctionManager()
14+
script.constantManager = CommonConstantManager()
15+
16+
val result = script.eval("randomInt(min = 1, max = 5)")
17+
if (result?.returnValue is ResultValue.Value) {
18+
println("Random value: ${result.returnValue}")
19+
}
20+
}
21+
```
22+
Java example
23+
```java
24+
import com.instancify.scriptify.api.exception.ScriptException;
25+
import com.instancify.scriptify.common.script.constant.CommonConstantManager;
26+
import com.instancify.scriptify.common.script.function.CommonFunctionManager;
27+
import kotlin.script.experimental.api.EvaluationResult;
28+
import kotlin.script.experimental.api.ResultValue;
29+
30+
public class Test {
31+
32+
public static void main(String[] args) throws ScriptException {
33+
KtsScript script = new KtsScript();
34+
script.setFunctionManager(new CommonFunctionManager());
35+
script.setConstantManager(new CommonConstantManager());
36+
37+
EvaluationResult result = script.eval("randomInt(min = 1, max = 5)");
38+
if (result != null) {
39+
if (result.getReturnValue() instanceof ResultValue.Value value) {
40+
System.out.println("Random value: " + value.getValue());
41+
}
42+
}
43+
}
44+
}
45+
```
46+
47+
This is a simple example of using the random number function. You can register your own functions and constants, or use ready-made ones from the [common module](https://github.com/Instancify/Scriptify/tree/master/common).
48+
49+
## Maven
50+
Adding repo:
51+
```xml
52+
<repositories>
53+
<repository>
54+
<id>instancify-repository-snapshots</id>
55+
<url>https://repo.instancify.app/snapshots</url>
56+
</repository>
57+
</repositories>
58+
```
59+
60+
Adding dependency:
61+
```xml
62+
<dependency>
63+
<groupId>com.instancify.scriptify.kts</groupId>
64+
<artifactId>kts</artifactId>
65+
<version>1.0.0-SNAPSHOT</version>
66+
</dependency>
67+
```
68+
69+
## Gradle
70+
Adding repo:
71+
```groovy
72+
maven {
73+
name "instancifyRepositorySnapshots"
74+
url "https://repo.instancify.app/snapshots"
75+
}
76+
```
77+
78+
Adding dependency:
79+
```groovy
80+
implementation "com.instancify.scriptify.kts:kts:1.0.0-SNAPSHOT"
81+
```

0 commit comments

Comments
 (0)