Documentation
¶
Overview ¶
pkg/plugin/plugin.go Plugin system for loading WebAssembly plugins at runtime.
WASM plugins work on all platforms (Windows, Linux, macOS) without CGO. Plugins can be written in TinyGo, Rust, C/C++, Zig, AssemblyScript, etc.
Usage from xxlang:
import "plugin/myplugin" myplugin.hello()
Building a WASM plugin:
tinygo build -o myplugin.wasm -target=wasi myplugin.go # or with Rust: cargo build --target wasm32-wasi --release
pkg/plugin/wasm_loader.go WebAssembly plugin loader using gowasm runtime. Works on all platforms including Windows without CGO.
pkg/plugin/wasm_plugin.go WebAssembly plugin wrapper that implements the Plugin interface.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Registry = struct { sync.RWMutex plugins map[string]Plugin }{ // contains filtered or unexported fields }
Registry tracks loaded plugins. It is safe for concurrent use.
Functions ¶
Types ¶
type Loader ¶
type Loader struct {
// contains filtered or unexported fields
}
Loader handles loading WASM plugin files.
func NewLoader ¶
func NewLoader() *Loader
NewLoader creates a new plugin loader with default search paths.
func (*Loader) Load ¶
Load loads a plugin by name. It first checks the registry, then searches for a .wasm file. Returns the plugin and any error encountered.
func (*Loader) LoadPath ¶ added in v0.4.19
LoadPath loads a plugin from a specific file path. The path should point to a .wasm file. This is useful when you want to load a plugin from a specific location without setting up search paths.
Example:
loader := plugin.NewLoader()
p, err := loader.LoadPath("./my-plugins/fib.wasm")
type Plugin ¶
type Plugin interface {
// Name returns the plugin name (used as plugin/name in imports).
Name() string
// Exports returns the module's exported symbols.
// The map keys are the names accessible from xxlang code.
Exports() map[string]objects.Object
}
Plugin is the interface that WASM plugins must implement.
type WasmPlugin ¶ added in v0.4.19
type WasmPlugin struct {
// contains filtered or unexported fields
}
WasmPlugin wraps a WASM module to implement the Plugin interface.
func NewWasmPlugin ¶ added in v0.4.19
func NewWasmPlugin(name string, module api.Module, rt interface{ Close(context.Context) error }) *WasmPlugin
NewWasmPlugin creates a new WasmPlugin from a loaded module.
func (*WasmPlugin) Close ¶ added in v0.4.19
func (p *WasmPlugin) Close(ctx context.Context) error
Close releases the WASM module resources.
func (*WasmPlugin) Exports ¶ added in v0.4.19
func (p *WasmPlugin) Exports() map[string]objects.Object
Exports returns the plugin's exported functions as Xxlang objects.
func (*WasmPlugin) Name ¶ added in v0.4.19
func (p *WasmPlugin) Name() string
Name returns the plugin name.