mirror of https://github.com/shadowfacts/ekt.git
Reuse ScriptEngine
This commit is contained in:
parent
fe378f453d
commit
05b7cd3892
|
@ -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…
Reference in New Issue