Skip to content
This repository was archived by the owner on Jan 4, 2025. It is now read-only.

y9vad9/script.kt

Repository files navigation

Maven metadata URL

script.kt

Convenient Kotlin Script wrapper. The main goal of this library is to simplify work with kotlin scripting.

Examples

Type-safe DSL

Simple DSL for scripts that do not need any customization, but just type-safe code.

moduleKts(mainScript = scriptOf(code = "..")) {
    setBaseClass<Foo>(arguments = listOf(Bar()))
    addImplicitReceiver<FooBar>(instance = FooBar())
}

External features

If you need to customize somehow your compilation you can use features system:

moduleKt(mainScript) {
    compilation.install(MavenDependenciesResolver)
    evaluation.install(/* some evaluation feature */)
}

Step-by-step configuration

If you need to divide your scripting processes you can use modular system:

val module = moduleOf(mainScript = scriptOf(code = "..."))
module.compilationConfiguration.apply { // for current state it is mutable
    baseClass = Foo::class
}
// now let's compile it
val compileResult = module.compile(compiler = JvmHostModuleCompiler())
if (compileResult.isError())
    throw RuntimeException("stub!")

val compiledModule = compileResult.valueOrThrow() // for this state compilation configuration is immutable
// let's add arguments of class `Foo`
compiledModule.evaluationConfiguration.apply { // it is mutable for current state
    baseClassArguments = listOf("...")
}

val evaluationResult = compiledModule.evaluate(evaluator = JvmHostModuleEvaluator())
if (evaluationResult.isError())
    throw RuntimeException("stub!")

// let's print our results
println((compileResult.reports + evaluationResult.reports).joinToString("\n") { it.render() })

Implementation

For first, we need to add repository:

repositories {
    maven("https://maven.y9vad9.com")
}

And then we need to add dependency:

dependencies {
    implementation("com.y9vad9.scriptkt:scriptkt:$version")
    // builtins (optional)
    implementation("com.y9vad9.scriptkt:maven-resolver:$version")
    implementation("com.y9vad9.scriptkt:import-script:$version")
}

About

Convenient kotlin script wrapper

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy