Hello! Are there any repos or examples of how to u...
# scripting
g
Hello! Are there any repos or examples of how to use Kotlin script engine in Intellij plugin dev? I’m trying to start with a simple code:
Copy code
setIdeaIoUseFallback()
val engine = ScriptEngineManager().getEngineByExtension("kts")!!
I’ve added dependencies and
/services/javax.script.ScriptEngineFactory
file. But the engine is actually null.
i
I'm tryin to do the same! Did you manage to get it working?
Copy code
object ScriptManager: ScriptEngineManager() {
    init {
        if (getEngineByExtension("kts") == null) {
            registerEngineExtension("kts", KotlinJsr223JvmLocalScriptEngineFactory())
        }
    }

}
As a workaround I use this code:
Copy code
ScriptManager.getEngineByExtension("kts")
g
Hello. I’m using
KotlinJsr223StandardScriptEngineFactory4Idea()
and it’s working
Or you can create more customized engine
Copy code
val factory = KotlinJsr223StandardScriptEngineFactory4Idea()
val engine: ScriptEngine = KotlinJsr223JvmScriptEngine4Idea(
    factory,
    jarNames,
    "kotlin.script.templates.standard.ScriptTemplateWithBindings",
    { ctx, argTypes -> ScriptArgsWithTypes(arrayOf(ctx.getBindings(ScriptContext.ENGINE_SCOPE)), argTypes ?: emptyArray()) },
    arrayOf(Map::class)
)
i
thanks for the reply!