add

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.

Validates that the number of type parameters matches the value's generic type parameter count.

Parameters

name

the variable name to bind in the script

value

the value to associate with the variable

types

the type parameters for generic types (e.g., for List<String>, pass typeOf<String>())

Throws

if the value is a local/anonymous class, or if the type parameter count is invalid