class Wasmer::Function

Overview

Function is 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 execution of the function.

Spec: https://webassembly.github.io/spec/core/exec/runtime.html#function-instances

Included Modules

Defined in:

wasmer/function.cr

Constructors

Instance Method Summary

Instance methods inherited from module Wasmer::WithExtern

to_extern : Extern to_extern

Constructor Detail

def self.new(store : Store, type : FunctionType, env : UserEnv, &func : FuncEnvProc) #

Instantiates a new Function in the given Store. It takes four arguments, the Store, the FunctionType, host environment and the definition for the Function. environment can be anything. It is Pointer(Void)

The function definition must be a native Crystal function with a Value array as its single argument. The function must return a Value array or raise an exception for abnormal conditions.

Note: Even if the function does not take any argument (or use any argument) it must receive a Value array as its single argument. At runtime, this array will be empty. The same applies to the result.


[View source]
def self.new(store : Store, type : FunctionType, &func : FuncProc) #

Instantiates a new Function in the given Store. It takes three arguments, the Store, the FunctionType and the definition for the Function.

The function definition must be a native Crystal function with a Value array as its single argument. The function must return a Value array or raise an exception for abnormal conditions.

Note: Even if the function does not take any argument (or use any argument) it must receive a Value array as its single argument. At runtime, this array will be empty. The same applies to the result.


[View source]

Instance Method Detail

def call(*params : Number) #

call the Function and return its result as native Crystal values.


[View source]
def native : Native #

turn the Function into a native Crystal function that can be called.


[View source]
def param_arity : UInt32 #

Returns the number of arguments the Function expects as per its definition


[View source]
def result_arity : UInt32 #

Returns the number of results the function will return


[View source]
def to_extern : Extern #

[View source]
def type : FunctionType #

[View source]