From bab5dc3b5aaca6d9992cb92f8478f3ec8f94f3c8 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 8 May 2018 20:21:12 +0200 Subject: [PATCH] fixed engine access --- .../kotlin/de/swirtz/ktsobjectloader/KtsObjectLoader.kt | 7 +++++-- .../de/swirtz/ktsobjectloader/KtsObjectLoaderTest.kt | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/de/swirtz/ktsobjectloader/KtsObjectLoader.kt b/src/main/kotlin/de/swirtz/ktsobjectloader/KtsObjectLoader.kt index 147a847..3b88781 100755 --- a/src/main/kotlin/de/swirtz/ktsobjectloader/KtsObjectLoader.kt +++ b/src/main/kotlin/de/swirtz/ktsobjectloader/KtsObjectLoader.kt @@ -6,8 +6,11 @@ import javax.script.ScriptEngineManager class KtsObjectLoader { - val engine = ScriptEngineManager().getEngineByExtension("kts") - as KotlinJsr223JvmLocalScriptEngine + companion object { + val engine = ScriptEngineManager().getEngineByExtension("kts") + as KotlinJsr223JvmLocalScriptEngine + + } inline fun load(script: String): T { val loaded: Any = engine.eval(script) diff --git a/src/test/kotlin/de/swirtz/ktsobjectloader/KtsObjectLoaderTest.kt b/src/test/kotlin/de/swirtz/ktsobjectloader/KtsObjectLoaderTest.kt index 6761cf2..c6f6d31 100755 --- a/src/test/kotlin/de/swirtz/ktsobjectloader/KtsObjectLoaderTest.kt +++ b/src/test/kotlin/de/swirtz/ktsobjectloader/KtsObjectLoaderTest.kt @@ -14,7 +14,7 @@ class KtsObjectLoaderTest { @Test fun `general ScriptEngineFactory test`() { - KtsObjectLoader().engine.factory.apply { + KtsObjectLoader.engine.factory.apply { assertEquals("kotlin", languageName) assertEquals(KotlinCompilerVersion.VERSION, languageVersion) assertEquals("kotlin", engineName) @@ -33,7 +33,7 @@ class KtsObjectLoaderTest { @Test fun `simple evaluations should work`() { - with(KtsObjectLoader().engine) { + with(KtsObjectLoader.engine) { val res1 = eval("val x = 3") assertNull(res1, "No returned value expected") val res2 = eval("x + 2")