Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't bind to engine #4

Open
npedot opened this issue Oct 22, 2020 · 1 comment
Open

Can't bind to engine #4

npedot opened this issue Oct 22, 2020 · 1 comment

Comments

@npedot
Copy link

npedot commented Oct 22, 2020

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)

@ligee
Copy link
Contributor

ligee commented Dec 28, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants