Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ScriptHost {
- private val jvmHost = BasicJvmScriptingHost()
- private val compilationConfiguration = createCompilationConfigurationFromTemplate(
- KotlinType(MyKotlinScript::class),
- defaultJvmScriptingHostConfiguration,
- CompilationConfiguration::class
- ) {
- jvm {
- dependenciesFromCurrentContext(
- // The classes in this JAR will not need to change during the server lifetime.
- "a-static-jar",
- // This jar contains a generated class whose content will change during the server lifetime.
- "a-dynamic-jar"
- )
- }
- }
- fun evaluate(code: String): CodeEvaluationResult {
- val scriptSource = code.toScriptSource(name = Constants.SCRIPT_FILE_NAME)
- val evaluationResult = jvmHost.eval(scriptSource, compilationConfiguration, null)
- val scriptInstance = (evaluationResult as? ResultWithDiagnostics.Success)
- ?.value
- ?.returnValue
- ?.scriptInstance
- return CodeEvaluationResult(scriptInstance, evaluationResult.reports)
- }
- }
Add Comment
Please, Sign In to add comment