Can't put variables for kts script engine in kotlin
I have this code:
fun main() {
with(ScriptEngineManager().getEngineByExtension("kts")) {
put("i", 3)
val res2 = eval("i")
println(res2)
}
}
which gives me this error:
Exception in thread "main" javax.script.ScriptException: error: unresolved reference: i
i
^
The evaluation works fine, if I dont try to reference the variable it all works fine. What am I doing wrong to add a variable?