Skip to content

Commit b3d3846

Browse files
committed
add Kotlin sample project
1 parent 14ab8d7 commit b3d3846

5 files changed

Lines changed: 51 additions & 1 deletion

File tree

examples/java-sample/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ tasks {
1414
withType<JavaCompile>().configureEach {
1515
options.release = 25
1616
}
17-
}
17+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
plugins {
2+
application
3+
alias(libs.plugins.kotlinJvm)
4+
}
5+
6+
dependencies {
7+
implementation(project(":interpreter"))
8+
}
9+
10+
application {
11+
mainClass = "MainKt"
12+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import tech.pacia.starlarkt.interpreter.Interpreter
2+
import tech.pacia.starlarkt.interpreter.StarInterpreterException
3+
import java.io.IOException
4+
import java.nio.file.Files
5+
import java.nio.file.Path
6+
import kotlin.system.exitProcess
7+
8+
fun main(args: Array<String>) {
9+
println("Hello, World!")
10+
11+
val verbose = true
12+
13+
if (args.size != 1) {
14+
System.err.println("must pass exactly 1 argument which is a path to a .star file")
15+
exitProcess(1)
16+
}
17+
18+
val filePath: Path = Path.of(args[0])
19+
val fileContent: String?
20+
try {
21+
fileContent = Files.readString(filePath)
22+
} catch (e: IOException) {
23+
throw RuntimeException(e)
24+
}
25+
26+
val interpreter = Interpreter()
27+
try {
28+
interpreter.execute(fileContent)
29+
} catch (e: StarInterpreterException) {
30+
if (verbose) {
31+
e.printStackTrace()
32+
} else {
33+
System.err.println(e.message)
34+
}
35+
}
36+
}

gradle/libs.versions.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ junit-platform-launcher = { module = "org.junit.platform:junit-platform-launcher
1010

1111
[plugins]
1212
kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
13+
kotlinJvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }

settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ dependencyResolutionManagement {
2020
include("app")
2121
include("interpreter")
2222
include(":examples:java-sample")
23+
include(":examples:kotlin-sample")

0 commit comments

Comments
 (0)