NAME

Wasm::Wasmtime::Extern - Wasmtime extern class

VERSION

version 0.24

SYNOPSIS

use Wasm::Wasmtime;

my $store = Wasm::Wasmtime::Store->new;
my $instance = Wasm::Wasmtime::Instance->new(
  Wasm::Wasmtime::Module->new($store->engine, wat => q{
    (module
      (func (export "foo") (param i32 i32) (result i32)
        local.get 0
        local.get 1
        i32.add)
      (memory (export "bar") 2 3)
    )
  }),
  $store,
);

my $foo = $instance->exports->foo;
print $foo->kind, "\n";  # func

my $bar = $instance->exports->bar;
print $bar->kind, "\n";  # memory

DESCRIPTION

This class represents an object exported from or imported into a Wasm::Wasmtime::Instance. This class cannot be created independently, but subclasses of this class can be retrieved from the Wasm::Wasmtime::Instance object. This is a base class and cannot be instantiated on its own.

In the modern Wasmtime C API an "extern" is a small tagged union value (wasmtime_extern_t) rather than a heap object. Each concrete subclass (Wasm::Wasmtime::Func, Wasm::Wasmtime::Memory, Wasm::Wasmtime::Global, Wasm::Wasmtime::Table) wraps the corresponding store-handle struct plus a reference to the owning Wasm::Wasmtime::Store.

METHODS

kind

my $string = $extern->kind;

Returns the extern kind as a string: func, global, table or memory.

is_func

is_global

is_table

is_memory

Return true for the matching kind.

from_extern

my $obj = Wasm::Wasmtime::Extern->from_extern($extern_data, $store);

Internal: given a wasmtime_extern_t struct (a Wasm::Wasmtime::FFI Wasm::Wasmtime::ExternData) and the owning Wasm::Wasmtime::Store, returns a Wasm::Wasmtime::Func, ::Global, ::Table or ::Memory object holding a private copy of the handle.

store

my $store = $extern->store;

Returns the Wasm::Wasmtime::Store that owns this extern.

context

my $context = $extern->context;

Returns the wasmtime_context_t pointer for this extern's store (internal use).

to_extern

my $extern_data = $extern->to_extern;

Internal: returns a fresh Wasm::Wasmtime::FFI Wasm::Wasmtime::ExternData (a wasmtime_extern_t) populated from this object's handle, for use as an import or with Wasm::Wasmtime::Linker->define.

SEE ALSO

Wasm
Wasm::Wasmtime

AUTHOR

Graham Ollis <plicease@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2020-2026 by Graham Ollis.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.