Skip to content

WrappedScript ​

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

Since1.7.0Not cancellable

Payload for scripts run through wrapScriptRun() 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 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 ​

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 ​

arg1: Tread-only#
the first argument supplied by the wrapped interface, or null for no-argument interfaces

arg2 ​

arg2: Uread-only#
the second argument supplied by a two-argument interface, or null otherwise

result ​

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 ​

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 ​

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) with a Float.

Parameters:

  • d: the value to return to the caller

setReturnInt ​

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 ​

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 ​

setReturnString(String s): void#
Sets a string result for a function or supplier wrapper.

Parameters:

  • s: the value to return to the caller

toString ​

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