Skip to content

WrappedScript ​

com.jsmacrosce.jsmacros.core.library.impl.classes.WrappedScript

Wraps a script run as a MethodWrapper for Java callback interfaces. Calls that return a value wait for the script even when the wrapper is asynchronous; calls that return nothing wait only for synchronous wrappers. Synchronous calls start a lock watchdog using the configured maximum lock time; if the lock remains held past that limit, the script context is closed.
The one-argument accept(Object) method passes an existing BaseEvent through;
other forms create an EventWrappedScript payload.

js
// Pass the wrapper to a Java API that accepts a callback.  
const wrapper = JsMacros.wrapScriptRun("adder.js");  
// Async wrappers skip waiting only for callbacks with no return value.  
const later = JsMacros.wrapScriptRunAsync("adder.js");

In the wrapped target script adder.js, a two-argument callback supplies arg1 and arg2 through its EventWrappedScript payload:

js
event.setReturnDouble(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
  • V: the type of the value the script returns to the caller

Constructors ​

new WrappedScript ​

new WrappedScript(Core<?, ?> runner, Function<BaseEvent, EventContainer<BaseScriptContext<?>>> f, boolean _async)#
Stores the runner and callback used by this wrapper and configures whether void-returning callbacks skip waiting.

Parameters:

  • runner: core used to create events and handle synchronous-call waiting
  • f: function invoked with the event to start the run and return its container for waiting
  • _async: whether void-returning callbacks skip waiting; value-returning callbacks wait regardless

Fields ​

_async ​

_async: booleanread-only#
Whether this wrapper skips waiting for methods that return nothing. Value-returning methods wait regardless of this flag.

f ​

Starts the run for the supplied event and returns its container, used for waiting and the lock watchdog. Events created by the wrapper are dispatched before this function is called.

Methods ​

accept ​

accept(T t): void#
Runs the script with one argument and discards its result. An existing BaseEvent is passed through unchanged; any other value becomes arg1 of an EventWrappedScript. The call waits unless this wrapper is asynchronous.

Parameters:

  • t: the argument to pass to the script, and the value of arg1 unless it is already an event
accept(T t, U u): void#
Runs the script with t as arg1 and u as arg2, discarding its result. Unlike accept, this always creates an EventWrappedScript. The call waits unless this wrapper is asynchronous.

Parameters:

  • t: the first argument, which the script reads as arg1
  • u: the second argument, which the script reads as arg2

apply ​

apply(T t): V#
Runs the script with t as arg1 and arg2 set to null, then returns the event's result unchanged. Unlike accept, it always creates an EventWrappedScript; it waits even when _async is set.

Parameters:

  • t: the argument to pass to the script, which the script reads as arg1
Returns: the event's result, or null if none was set
apply(T t, U u): V#
Runs the script with t as arg1 and u as arg2, then returns the event's result unchanged. It waits even when _async is set.

Parameters:

  • t: the first argument, which the script reads as arg1
  • u: the second argument, which the script reads as arg2
Returns: the event's result, or null if none was set

compare ​

compare(T o1, T o2): int#
Runs the script with o1 as arg1 and arg2 set to null; the comparator's second value, o2, is not passed to the script. The result is cast to Integer, and the call waits even when _async is set. A non-Integer result, including null, causes a ClassCastException.

Parameters:

  • o1: the first of the two values, which the script reads as arg1
  • o2: the second of the two values, which is not passed on to the script
Returns: the script's result cast to an int, so null fails here as well

get ​

get(): V#
Runs the script with both arg1 and arg2 set to null, then returns its result unchanged. The call waits even when _async is set.
Returns: whatever the script put on the event's result, which is null unless the script set it

run ​

run(): void#
Runs the script with both arg1 and arg2 set to null; its result is discarded. The caller waits unless _async is set.

test ​

test(T t): boolean#
Runs the script with t as arg1 and arg2 set to null, then casts the result to Boolean. It waits even when _async is set; a non-Boolean result, including null, causes a ClassCastException.

Parameters:

  • t: the argument to pass to the script, which the script reads as arg1
Returns: the script's result cast to a boolean
test(T t, U u): boolean#
Runs the script with t as arg1 and u as arg2, then casts its result to Boolean. The call waits even when _async is set; a non-Boolean result, including null, causes a ClassCastException.

Parameters:

  • t: the first argument, which the script reads as arg1
  • u: the second argument, which the script reads as arg2
Returns: the script's result cast to a boolean, so null fails here as well