# WrappedScript

`com.jsmacrosce.jsmacros.core.event.impl.EventWrappedScript`

**Since:** 1.7.0

**Cancellable:** No. Calling `event.cancel()` throws `UnsupportedOperationException`.

Payload for scripts run through [wrapScriptRun()](../../../../../../../libraries/com/jsmacrosce/jsmacros/core/library/impl/FJsMacros.md#com.jsmacrosce.jsmacros.core.library.impl.FJsMacros_wrapScriptRun-String-)
 or `wrapScriptRunAsync`. The wrapper dispatches this event before running the script.  
 Arguments depend on the Java functional interface: no-argument interfaces provide two nulls,  
 one-argument interfaces provide `arg1` and a null `arg2`, and two-argument
 interfaces provide both, except `Comparator`, which forwards only its first value.  
 The wrapped script can set [result](#com.jsmacrosce.jsmacros.core.event.impl.EventWrappedScript_result) for interfaces that return a value; consumers and
 runnables ignore it.  
 ```js
// In a wrapped two-argument function script, return a result to the Java caller.  
event.setReturnInt(Number(event.arg1) + Number(event.arg2));  
 ```

## Type Parameters

- `T`: the type the first argument arrives as
- `U`: the type the second argument arrives as, and `null` unless the wrapper was
            passed as a two argument interface
- `R`: the type of the value the script returns to the caller

## Constructors

### new EventWrappedScript {#com.jsmacrosce.jsmacros.core.event.impl.EventWrappedScript_constructor-Core-T-U-}

```js
new EventWrappedScript(Core<?, ?> runner, T arg1, U arg2)
```

Stores the event's associated core and the supplied arguments without dispatching the event
 or starting a script.

**Parameters:**
- `runner`: the core associated with this event
- `arg1`: the supplied first argument
- `arg2`: the supplied second argument

## Fields

### arg1 {#com.jsmacrosce.jsmacros.core.event.impl.EventWrappedScript_arg1}

```js
arg1: T
```

the first argument supplied by the wrapped interface, or `null` for no-argument
 interfaces

### arg2 {#com.jsmacrosce.jsmacros.core.event.impl.EventWrappedScript_arg2}

```js
arg2: U
```

the second argument supplied by a two-argument interface, or `null` otherwise

### result {#com.jsmacrosce.jsmacros.core.event.impl.EventWrappedScript_result}

```js
result: R
```

Value supplied by the script for the wrapped Java interface. Value-returning interfaces
 read it after the script finishes: functions and suppliers return it as-is, predicates cast
 it to `Boolean`, and comparators cast it to `Integer`. Consumers and runnables
 ignore it; an incompatible predicate or comparator value fails in the Java caller.

## Methods

### setReturnBoolean {#com.jsmacrosce.jsmacros.core.event.impl.EventWrappedScript_setReturnBoolean-boolean-}

```js
setReturnBoolean(boolean b): void
```

Sets a boolean result, as read by `Predicate` and `BiPredicate` wrappers. Other
 result types may fail their caller-side cast.

**Parameters:**
- `b`: the value to return to the caller

### setReturnDouble {#com.jsmacrosce.jsmacros.core.event.impl.EventWrappedScript_setReturnDouble-double-}

```js
setReturnDouble(double d): void
```

Sets a double result, boxed as `Double` when returned by a function or supplier. To
 return a `Float`, use [setReturnObject(java.lang.Object)](#com.jsmacrosce.jsmacros.core.event.impl.EventWrappedScript_setReturnObject-Object-) with a `Float`.

**Parameters:**
- `d`: the value to return to the caller

### setReturnInt {#com.jsmacrosce.jsmacros.core.event.impl.EventWrappedScript_setReturnInt-int-}

```js
setReturnInt(int i): void
```

Sets an integer result, as read by `Comparator` wrappers. Function and supplier
 wrappers return the boxed value as-is; an incompatible comparator result fails its caller-side cast.

**Parameters:**
- `i`: the value to return to the caller

### setReturnObject {#com.jsmacrosce.jsmacros.core.event.impl.EventWrappedScript_setReturnObject-Object-}

```js
setReturnObject(Object o): void
```

Sets an arbitrary result value. The wrapped interface may cast it to a particular type.

**Parameters:**
- `o`: the value to return to the caller

### setReturnString {#com.jsmacrosce.jsmacros.core.event.impl.EventWrappedScript_setReturnString-String-}

```js
setReturnString(String s): void
```

Sets a string result for a function or supplier wrapper.

**Parameters:**
- `s`: the value to return to the caller

### toString {#com.jsmacrosce.jsmacros.core.event.impl.EventWrappedScript_toString-}

```js
toString(): String
```

Returns diagnostic text containing the event name and formatted `arg1` and `arg2`
 values. This is not a stable serialization or valid quoted JSON, and does not include
 `result`.

**Returns:** event-name and argument diagnostic text
