Add configuration option for script host to oliveProgram

This commit is contained in:
Edwin Jakobs
2020-05-18 15:25:54 +02:00
parent f18dced653
commit c64562999a
3 changed files with 5 additions and 4 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

View File

@@ -2,6 +2,7 @@ import org.openrndr.Extension
import org.openrndr.application import org.openrndr.application
import org.openrndr.color.ColorRGBa import org.openrndr.color.ColorRGBa
import org.openrndr.extensions.SingleScreenshot import org.openrndr.extensions.SingleScreenshot
import org.openrndr.extra.olive.OliveScriptHost
import org.openrndr.extra.olive.oliveProgram import org.openrndr.extra.olive.oliveProgram
import kotlin.math.cos import kotlin.math.cos
@@ -11,7 +12,7 @@ fun main() {
width = 1280 width = 1280
height = 720 height = 720
} }
oliveProgram { oliveProgram(scriptHost = OliveScriptHost.JSR223) {
extend { extend {
drawer.clear(ColorRGBa.GRAY) drawer.clear(ColorRGBa.GRAY)
drawer.fill = ColorRGBa.WHITE drawer.fill = ColorRGBa.WHITE

View File

@@ -7,7 +7,7 @@ import java.nio.file.Files
import java.nio.file.Paths import java.nio.file.Paths
import kotlin.streams.toList import kotlin.streams.toList
open class OliveProgram(private val sourceLocation: String) : Program() { open class OliveProgram(private val sourceLocation: String, private val scriptHost: OliveScriptHost) : Program() {
val olive = extend(Olive<OliveProgram>(scriptMode = ScriptMode.OLIVE_PROGRAM)) { val olive = extend(Olive<OliveProgram>(scriptMode = ScriptMode.OLIVE_PROGRAM)) {
script = sourceLocation script = sourceLocation
} }
@@ -19,7 +19,7 @@ fun stackRootClassName(thread: Thread = Thread.currentThread(), sanitize: Boolea
return if (sanitize) rootClass.replace(Regex("Kt$"), "") else rootClass return if (sanitize) rootClass.replace(Regex("Kt$"), "") else rootClass
} }
fun ApplicationBuilder.oliveProgram(init: OliveProgram.() -> Unit): OliveProgram { fun ApplicationBuilder.oliveProgram(scriptHost: OliveScriptHost = OliveScriptHost.JSR223_REUSE, init: OliveProgram.() -> Unit): OliveProgram {
val rootClassName = stackRootClassName(sanitize = true).split(".").last() val rootClassName = stackRootClassName(sanitize = true).split(".").last()
var sourceLocation = "src/main/kotlin/$rootClassName.kt" var sourceLocation = "src/main/kotlin/$rootClassName.kt"
@@ -33,7 +33,7 @@ fun ApplicationBuilder.oliveProgram(init: OliveProgram.() -> Unit): OliveProgram
error("multiple source candidates found: $otherCandidates") error("multiple source candidates found: $otherCandidates")
} }
} }
program = object : OliveProgram(sourceLocation) { program = object : OliveProgram(sourceLocation, scriptHost) {
override fun setup() { override fun setup() {
super.setup() super.setup()
init() init()