Package io.github.eutro.wasm2j.embed
Interface ExternVal
- All Known Implementing Classes:
Func.HandleFunc,Global.BoxGlobal,Global.HandleGlobal,Memory.ByteBufferMemory,Memory.HandleMemory,Table.AbstractArrayTable,Table.ArrayTable,Table.HandleTable
public interface ExternVal
An extern, a value that can be exported from a module instance, or provided as an import.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <F> ExternValCreate a functionExternValfrom an instance of a functional interface.static ExternValfunc(MethodHandle handle) Create a functionExternValdirectly from aMethodHandle.default FuncGet this as a function, or throw an exception.default GlobalGet this as a global, or throw an exception.default MethodHandlegetAsHandle(MethodType type) Get this function as a method handle of the given type.default MethodHandleGet the underlying method handle of this function.default MemoryGet this as a memory, or throw an exception.default TableGet this as a table, or throw an exception.@NotNull ExternTypegetType()Get the type of this extern.default booleanmatchesType(@Nullable ExternType expected, ExternType.Kind kind) Check whether this extern matches the given expected type.
-
Method Details
-
getType
Get the type of this extern.- Returns:
- The type.
-
matchesType
Check whether this extern matches the given expected type.- Parameters:
expected- The expected type, or null if only the kind should be matched.kind- The expected kind.- Returns:
- Whether the type matched.
-
getAsTable
Get this as a table, or throw an exception.- Returns:
- The table.
-
getAsGlobal
Get this as a global, or throw an exception.- Returns:
- The global.
-
getAsMemory
Get this as a memory, or throw an exception.- Returns:
- The memory.
-
getAsFunc
Get this as a function, or throw an exception.- Returns:
- The function.
-
getAsHandleRaw
Get the underlying method handle of this function.Throws an exception if this is not a function.
- Returns:
- The method handle.
-
getAsHandle
Get this function as a method handle of the given type.Throws an exception if this is not a function, or cannot be cast to the type.
- Parameters:
type- The type of the handle.- Returns:
- The cast handle.
-
func
Create a functionExternValdirectly from aMethodHandle.- Parameters:
handle- The method handle.- Returns:
- The
ExternVal.
-
func
Create a functionExternValfrom an instance of a functional interface.The class provided must be suitable for an
FunctionalInterfaceannotation. That is, it must be an interface with exactly one abstract method.This method is provided to make creating function
ExternVals easy from Java.// using existing functional interfaces ExternVal.func(Runnable.class, () -> System.out.println("Hello, world!")); ExternVal.func(IntUnaryOperator.class, x -> -x); // using ad-hoc functional interfaces interface IntIntDoubleDouble { double call(int x, int y, double z); } ExternVal.func(IntIntDoubleDouble.class, (x, y, z) -> x + y * z);- Type Parameters:
F- The type of the function.- Parameters:
functionalInterfaceClass- The functional interface class.f- An instance of the functional interface.- Returns:
- The
ExternVal.
-