KotlinScript

class KotlinScript(nullGlobalContext: Boolean = false) : AbstractScript, Closeable

A script engine wrapper for dynamically evaluating Kotlin source code using the kts extension.

Manages variable bindings via the JSR 223 Bindings mechanism, generates Kotlin val declarations that cast bound values to their appropriate types, and prepends import statements to evaluated code.

Common literal JVM-termination calls (System.exit, exitProcess, Runtime.getRuntime().exit/halt) are rejected on a best-effort basis via ScriptGuards; bare System.exit is additionally shadowed by the auto-imported System object. This is a convenience against accidental termination, not a security sandbox (see ScriptGuards) — run untrusted scripts in an isolated process or JVM.

Parameters

nullGlobalContext

if true, sets the global scope bindings to null on initialization

See also

Constructors

Link copied to clipboard
constructor(nullGlobalContext: Boolean = false)

Properties

Link copied to clipboard
Link copied to clipboard

The Kotlin import statements for all registered import classes (the import list is fixed, so this is computed once).

Link copied to clipboard

Generates Kotlin val declarations that retrieve bound variables from the engine's bindings and cast them to their appropriate types with type parameters.

Functions

Link copied to clipboard
open fun add(name: String, value: Any, vararg types: KType)
Link copied to clipboard
open override fun close()
Link copied to clipboard
Link copied to clipboard
open fun params(name: String, types: Array<out KType>): String
Link copied to clipboard
fun resetContext(nullGlobalContext: Boolean)