Add alternate scripting host (non jsr-223) to orx-olive
This commit is contained in:
@@ -1,4 +1,17 @@
|
|||||||
dependencies {
|
dependencies {
|
||||||
compile project(":orx-file-watcher")
|
compile project(":orx-file-watcher")
|
||||||
|
|
||||||
|
// -- JSR 223, old style script loader
|
||||||
compile "org.jetbrains.kotlin:kotlin-scripting-jsr223:$kotlinVersion"
|
compile "org.jetbrains.kotlin:kotlin-scripting-jsr223:$kotlinVersion"
|
||||||
|
|
||||||
|
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
|
||||||
|
compile "org.jetbrains.kotlin:kotlin-scripting-jvm-host-embeddable:$kotlinVersion"
|
||||||
|
compile "org.jetbrains.kotlin:kotlin-scripting-common:$kotlinVersion"
|
||||||
|
compile "org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable:$kotlinVersion"
|
||||||
|
compile "org.jetbrains.kotlin:kotlin-compiler-embeddable:$kotlinVersion"
|
||||||
|
compile "org.jetbrains.kotlin:kotlin-compiler:$kotlinVersion"
|
||||||
|
// compile "org.jetbrains.kotlin:kotlin-script-util:$kotlinVersion"
|
||||||
|
// compile "org.jetbrains.kotlin:kotlin-main-kts:$kotlinVersion"
|
||||||
|
// compile "org.jetbrains.kotlin:kotlin-scripting-dependencies:$kotlinVersion"
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -98,7 +98,7 @@ class Olive<P : Program>(val resources: Resources? = null) : Extension {
|
|||||||
try {
|
try {
|
||||||
val futureFunc = GlobalScope.async {
|
val futureFunc = GlobalScope.async {
|
||||||
val start = System.currentTimeMillis()
|
val start = System.currentTimeMillis()
|
||||||
val f = loadFromScript<P.() -> Unit>(it)
|
val f = loadFromScriptKSH<P.() -> Unit>(it)
|
||||||
val end = System.currentTimeMillis()
|
val end = System.currentTimeMillis()
|
||||||
logger.info { "loading script took ${end - start}ms" }
|
logger.info { "loading script took ${end - start}ms" }
|
||||||
f
|
f
|
||||||
|
|||||||
34
orx-olive/src/main/kotlin/ScriptObjectLoaderKSH.kt
Normal file
34
orx-olive/src/main/kotlin/ScriptObjectLoaderKSH.kt
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
package org.openrndr.extra.olive
|
||||||
|
|
||||||
|
import java.io.File
|
||||||
|
import kotlin.script.experimental.api.*
|
||||||
|
import kotlin.script.experimental.host.BasicScriptingHost
|
||||||
|
import kotlin.script.experimental.host.toScriptSource
|
||||||
|
import kotlin.script.experimental.jvm.dependenciesFromCurrentContext
|
||||||
|
import kotlin.script.experimental.jvm.jvm
|
||||||
|
import kotlin.script.experimental.jvmhost.BasicJvmScriptingHost
|
||||||
|
import kotlin.script.experimental.jvmhost.createJvmCompilationConfigurationFromTemplate
|
||||||
|
import kotlin.script.templates.standard.SimpleScriptTemplate
|
||||||
|
|
||||||
|
internal fun evalScriptWithConfiguration(
|
||||||
|
script: String,
|
||||||
|
host: BasicScriptingHost = BasicJvmScriptingHost(),
|
||||||
|
body: ScriptCompilationConfiguration.Builder.() -> Unit = {}
|
||||||
|
): ResultWithDiagnostics<EvaluationResult> {
|
||||||
|
val compilationConfiguration = createJvmCompilationConfigurationFromTemplate<SimpleScriptTemplate>(body = body)
|
||||||
|
return host.eval(script.toScriptSource(), compilationConfiguration, null)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T> loadFromScriptKSH(
|
||||||
|
script: File,
|
||||||
|
host: BasicScriptingHost = BasicJvmScriptingHost(),
|
||||||
|
body: ScriptCompilationConfiguration.Builder.() -> Unit = {
|
||||||
|
|
||||||
|
jvm {
|
||||||
|
dependenciesFromCurrentContext(wholeClasspath = true)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
): T = (evalScriptWithConfiguration(script.readText(), host, body).valueOrThrow().returnValue as ResultValue.Value).value as T
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user