RayeW47
05/12/2021, 12:02 AMilya.chernikov
05/14/2021, 3:18 PMRayeW47
05/26/2021, 1:38 AMorg.jetbrains.kotlin:kotlin-scripting-common
org.jetbrains.kotlin:kotlin-script-runtime
More specifically I have been looking at kotlin.script.experimental.annotations.KotlinScript
as it seems to be what I am looking for. Looking at it and kotlin.script.experimental.api.ScriptCompilationConfiguration
lead me to believe I can achieve what I asked about, assuming it is set up properly with the build system (which I am also new to, advanced building systems like gradle and maven), which would be to say create a custom configuration ScriptCompilationConfiguration
that imports certain things by default and only import them by default when inside a file of a certain extension which you can define KotlinScript.fileExtension
For example I have abstract class Dog { fun woof() { println("woof") }
which I want to set as one of the ScriptCompilationConfiguration.implicitReceivers
and be able to access it's insides in a file with dog.kts
extension and I can use it at runtime by passing a Dog
to it. I'm not sure if I am explaining this properly, but I know what I am trying to achieve I just don't know how to achieve itilya.chernikov
06/14/2021, 7:47 AMString
(which is not a good example indeed, I have to replace it with something more sensible, but it shows the mechanics anyway for now).
And in this line - https://github.com/Kotlin/kotlin-script-examples/blob/master/jvm/simple-main-kts/simple-main-kts/src/main/kotlin/org/jetbrains/kotlin/script/examples/simpleMainKts/scriptDef.kt#L85 the evaluation configuration defines actual object passed as this receiver (empty string in this case).
You may change the configuration dynamically, e.g. you can configure a callback (as in this line - https://github.com/Kotlin/kotlin-script-examples/blob/master/jvm/simple-main-kts/simple-main-kts/src/main/kotlin/org/jetbrains/kotlin/script/examples/simpleMainKts/scriptDef.kt#L86) or you can pass a base evaluation configuration to eval
.RayeW47
06/18/2021, 1:12 PM