Skip to content

Commit

Permalink
fixed engine access
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon committed May 8, 2018
1 parent 0326359 commit bab5dc3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/main/kotlin/de/swirtz/ktsobjectloader/KtsObjectLoader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 <reified T> load(script: String): T {
val loaded: Any = engine.eval(script)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
Expand Down

0 comments on commit bab5dc3

Please sign in to comment.