NAME

Wasm::Wasmer::Function - WebAssembly function

SYNOPSIS

my $module = Wasm::Wasmer::Module->new($wasm_bin);

my $func = $module->create_instance()->export('somefunc');

my @got = $func->call(2, 34);

DESCRIPTION

This class represents a WebAssembly function: either an exported one or a Perl callback to give to WebAssembly. It is not instantiated directly.

This class subclasses Wasm::Wasmer::Extern.

METHODS

@RETURNS = OBJ->call(@INPUTS)

Calls the function, passing the given @INPUTS and returning the returned values as a list.

@INPUTS must match the function’s export signature in both type and length; e.g., if a function expects (i32, f64) and you pass (4.3, 12), or give too many or too few parameters, an exception will be thrown that explains the discrepancy.

If the function returns multiple items, scalar context is forbidden. (Void context is always allowed, though.)

Notes

  • If OBJ is an export from a WASI-enabled WASM instance then the WASI start function will run automatically if needed prior to running OBJ.