AbstractScript

abstract class AbstractScript(extension: String, nullGlobalContext: Boolean) : AbstractEngine

Abstract base class for script execution that supports named variable bindings with type parameters.

Manages a map of named values and their associated type parameters, generates parameter declarations for the target language, and handles context resets between evaluations.

Subclasses call prepare at the start of every evaluation, which checks the code and binds the variables added since the last evaluation. Variables can therefore be added at any time. Adding variables, resetting, and evaluating are synchronized on the instance.

Parameters

extension

the file extension used to look up the script engine (e.g., "kts", "py", "java")

nullGlobalContext

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

Constructors

Link copied to clipboard
constructor(extension: String, nullGlobalContext: Boolean)

Properties

Link copied to clipboard

The underlying JSR 223 script engine for this extension.

Functions

Link copied to clipboard
open fun add(name: String, value: Any, vararg types: KType)

Adds a named variable with an associated value and optional type parameters to the script context.

Link copied to clipboard
open override fun close()

Releases resources held by the engine. The default does nothing; engines that hold resources override it.

Link copied to clipboard
open fun params(name: String, types: Array<out KType> = typeMap[name] ?: error("No type parameters registered for $name")): String

Generates the type argument string (e.g., <kotlin.Int, kotlin.String>) for the variable with the given name, rendering each type with renderType.

Link copied to clipboard
fun resetContext(nullGlobalContext: Boolean)

Resets the script engine context, clearing all variable and type mappings.

Link copied to clipboard
open fun resetForReuse(nullGlobalContext: Boolean)

Prepares this instance for its next user by resetting the context and any other per-user state. AbstractScriptPool calls it when an instance is returned to the pool; subclasses that hold more state, such as imports, extend it.