Can't bind to engine
npedot opened this issue · comments
import org.junit.Test
import javax.script.ScriptEngineManager
import kotlin.test.assertEquals
class ScriptTest {
@Test
fun testSimpleEval() {
val engine = ScriptEngineManager().getEngineByExtension("kts")!!
val res = engine.eval("2+4")
assertEquals(6,res)
}
@Test
fun testSimpleBinding() {
val engine = ScriptEngineManager().getEngineByExtension("kts")!!
engine.put("hello","world")
val res = engine.eval("hello")
assertEquals("world",res)
}
}
I've got
javax.script.ScriptException: Unresolved reference: hello
at org.jetbrains.kotlin.cli.common.repl.KotlinJsr223JvmScriptEngineBase.compileAndEval(KotlinJsr223JvmScriptEngineBase.kt:65)
at org.jetbrains.kotlin.cli.common.repl.KotlinJsr223JvmScriptEngineBase.eval(KotlinJsr223JvmScriptEngineBase.kt:31)
What version of the Kotlin libs you're yousing?
Have you tried the examples and tests from this repo 1:1? There is a test - https://github.com/Kotlin/kotlin-script-examples/blob/master/jvm/jsr223/jsr223-simple/src/test/kotlin/org/jetbrains/kotlin/script/examples/jvm/jsr223/simple/test/simpleJsr223Test.kt#L29 - with exactly this functionality here, and it works for me.