kotlin.script.experimental.jvmhost.BasicJvmScriptingHost.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlin-main-kts Show documentation
Show all versions of kotlin-main-kts Show documentation
Kotlin "main" script definition
/*
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@file:Suppress("unused")
package kotlin.script.experimental.jvmhost
import kotlin.script.experimental.api.*
import kotlin.script.experimental.host.*
import kotlin.script.experimental.jvm.BasicJvmScriptEvaluator
import kotlin.script.experimental.jvm.defaultJvmScriptingHostConfiguration
open class BasicJvmScriptingHost(
val baseHostConfiguration: ScriptingHostConfiguration? = null,
compiler: JvmScriptCompiler = JvmScriptCompiler(baseHostConfiguration.withDefaultsFrom(defaultJvmScriptingHostConfiguration)),
evaluator: ScriptEvaluator = BasicJvmScriptEvaluator()
) : BasicScriptingHost(compiler, evaluator) {
inline fun evalWithTemplate(
script: SourceCode,
noinline compilation: ScriptCompilationConfiguration.Builder.() -> Unit = {},
noinline evaluation: ScriptEvaluationConfiguration.Builder.() -> Unit = {}
): ResultWithDiagnostics {
val definition =
createJvmScriptDefinitionFromTemplate(baseHostConfiguration, compilation, evaluation)
return eval(script, definition.compilationConfiguration, definition.evaluationConfiguration)
}
}
inline fun createJvmCompilationConfigurationFromTemplate(
baseHostConfiguration: ScriptingHostConfiguration? = null,
noinline body: ScriptCompilationConfiguration.Builder.() -> Unit = {}
): ScriptCompilationConfiguration = createCompilationConfigurationFromTemplate(
KotlinType(T::class),
baseHostConfiguration.withDefaultsFrom(defaultJvmScriptingHostConfiguration),
ScriptCompilationConfiguration::class,
body
)
inline fun createJvmEvaluationConfigurationFromTemplate(
baseHostConfiguration: ScriptingHostConfiguration? = null,
noinline body: ScriptEvaluationConfiguration.Builder.() -> Unit = {}
): ScriptEvaluationConfiguration = createEvaluationConfigurationFromTemplate(
KotlinType(T::class),
baseHostConfiguration.withDefaultsFrom(defaultJvmScriptingHostConfiguration),
ScriptEvaluationConfiguration::class,
body
)
inline fun createJvmScriptDefinitionFromTemplate(
baseHostConfiguration: ScriptingHostConfiguration? = null,
noinline compilation: ScriptCompilationConfiguration.Builder.() -> Unit = {},
noinline evaluation: ScriptEvaluationConfiguration.Builder.() -> Unit = {}
): ScriptDefinition = createScriptDefinitionFromTemplate(
KotlinType(T::class),
baseHostConfiguration.withDefaultsFrom(defaultJvmScriptingHostConfiguration),
ScriptCompilationConfiguration::class,
compilation,
evaluation
)