Browse Source

Reuse ScriptEngine

master
Shadowfacts 5 years ago
parent
commit
05b7cd3892
Signed by: shadowfacts GPG Key ID: 94A5AB95422746E5
  1. 7
      src/main/kotlin/net/shadowfacts/ekt/EKT.kt

7
src/main/kotlin/net/shadowfacts/ekt/EKT.kt

@ -3,6 +3,7 @@ package net.shadowfacts.ekt
import java.io.File
import javax.script.ScriptContext
import javax.script.ScriptEngineManager
import javax.script.SimpleScriptContext
/**
* @author shadowfacts
@ -35,6 +36,10 @@ _result.toString()
ScriptEngineManager()
}
private val engine by lazy {
manager.getEngineByExtension("kts")
}
fun render(template: String, dumpGeneratedScript: File? = null, dataProvider: DataProviderContext.() -> Unit): String {
@Suppress("NAME_SHADOWING")
var template = template
@ -75,7 +80,7 @@ _result.toString()
}
internal fun eval(script: String, data: Map<String, TypedValue> = mapOf()): Any? {
val engine = manager.getEngineByExtension("kts")
engine.context = SimpleScriptContext()
val bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE)
bindings.putAll(data)

Loading…
Cancel
Save