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> ExternVal
Create a functionExternVal
from an instance of a functional interface.static ExternVal
func
(MethodHandle handle) Create a functionExternVal
directly from aMethodHandle
.default Func
Get this as a function, or throw an exception.default Global
Get this as a global, or throw an exception.default MethodHandle
getAsHandle
(MethodType type) Get this function as a method handle of the given type.default MethodHandle
Get the underlying method handle of this function.default Memory
Get this as a memory, or throw an exception.default Table
Get this as a table, or throw an exception.@NotNull ExternType
getType()
Get the type of this extern.default boolean
matchesType
(@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 functionExternVal
directly from aMethodHandle
.- Parameters:
handle
- The method handle.- Returns:
- The
ExternVal
.
-
func
Create a functionExternVal
from an instance of a functional interface.The class provided must be suitable for an
FunctionalInterface
annotation. That is, it must be an interface with exactly one abstract method.This method is provided to make creating function
ExternVal
s 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
.
-