Hi there! I have been using the embedded Kotlin sc...
# scripting
o
Hi there! I have been using the embedded Kotlin script compiler for a longer time for an internal DSL. So, I do compile scripts (strings) just fine internally and run them. I also have used experimental context receviers for quite some time in my DSL. The Gradle project enables this using the normal
freeCompiler
arguments for the Kotlin tasks. But now, I seem to have reached yet another level: I added one specific DSL extension function to my language that needs to use a context receiver for the DSL language itself - and compiling it using the script compiler yields the known message:
Copy code
ERROR To use contextual declarations, specify the `-Xcontext-receivers` compiler option (unnamed.trala.kts:3:1)
The way I use the compiler internally is this function I wrote:
Copy code
fun evalTransformation(script: String, name: String?): ResultWithDiagnostics<EvaluationResult> {
    val compilationConfiguration = createJvmCompilationConfigurationFromTemplate<TralaScript>()
    return BasicJvmScriptingHost().eval(script.toScriptSource(name), compilationConfiguration, null)
}

@KotlinScript(fileExtension = "trala.kts", compilationConfiguration = TralaScriptConfiguration::class)
abstract class TralaScript

object TralaScriptConfiguration : ScriptCompilationConfiguration(
    {
        defaultImports(tralaDefaultImports)

        jvm {
            jvmTarget("11")                   
            updateClasspath(...)
        }
    }
)
I am searching, but not finding... which element here would be the key to enabling the context receivers? Is it the compilationConfiguration, so my own
ScriptCompilationConfiguration
that I defined, or is it the
BasicJvmScriptingHost
first parameter, named
baseHostConfiguration
? Do I find a named function called "contextReceivers" anywhere or do I need to pull tricks somewhere? Any help is appreciated!