Struct wasmer_ruby::Wasmer::Function
source · pub struct Function;Expand description
Represents a WebAssembly function instance.
A function instance is the runtime representation of a
function. It effectively is a closure of the original function
(defined in either the host or the WebAssembly module) over
the runtime Instance of its originating Module.
The module instance is used to resolve references to other definitions during executing of the function.
Specification: https://webassembly.github.io/spec/core/exec/runtime.html#function-instances
Note that the function can be invoked/called by the host only
when it is an exported function (see Exports to see an
example).
Example
To build a Function, we need its type. Function
understands Symbol, Proc, and Lambda.
First, a function through a symbol:
def foo(x)
x + 1
end
function = Wasmer::Function.new(
Wasmer::Store.new,
# A symbol.
method(:foo),
Wasmer::FunctionType.new([Wasmer::Type::I32], [])
)Second, a function through a proc as a lambda:
function = Wasmer::Function.new(
Wasmer::Store.new,
# A lambda.
-> (x) { x + 1 },
Wasmer::FunctionType.new([Wasmer::Type::I32], [])
)Third, a function through a proc:
function = Wasmer::Function.new(
Wasmer::Store.new,
# A proc.
Proc.new { |x| x + 1 },
Wasmer::FunctionType.new([Wasmer::Type::I32], [])
)Implementations§
source§impl Function
impl Function
sourcepub fn new(store: Store, function: Any, function_type: FunctionType) -> Self
pub fn new(store: Store, function: Any, function_type: FunctionType) -> Self
Creates a new Function. The function can be of kind
Symbol, Proc or Lambda.
sourcepub fn call(x0: Any, x1: Any, x2: Any, etc: Any) -> Any
pub fn call(x0: Any, x1: Any, x2: Any, etc: Any) -> Any
Calls the function with arguments. It returns zero or more results.
sourcepub fn type(&self) -> FunctionType
pub fn type(&self) -> FunctionType
Returns the function type.