Documentation
¶
Overview ¶
Package wazero provides a script engine implementation using the wazero WebAssembly runtime (https://github.com/wazero/wazero). It allows executing WebAssembly (WASM) modules as scripts at runtime.
WebAssembly is a binary format, so the "code" passed to LoadString / ExecuteString / loaded from Source is raw WASM bytes (Go strings can hold arbitrary bytes, so the []byte ↔ string conversion is lossless).
Construction:
eng, _ := wazero.New(ctx) eng.Init(ctx) eng.LoadString(ctx, "add.wasm", string(wasmBytes)) result, _ := eng.Execute(ctx)
After Execute, use CallFunction to invoke exported WASM functions:
result, _ := eng.CallFunction(ctx, "add", uint64(3), uint64(4))
The engine supports hot-reload via StartWatch/StopWatch when the bound Source implements the Watcher interface.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrWazeroEngineNotInitialized is returned when an operation is invoked // before Init or after Close. ErrWazeroEngineNotInitialized = errors.New("wazero engine not initialized") // ErrWazeroEngineAlreadyInitialized is returned when Init is called on an // already-initialized engine. ErrWazeroEngineAlreadyInitialized = errors.New("wazero engine already initialized") // ErrWazeroRuntimeNotInitialized is returned when the underlying wazero // runtime is nil. ErrWazeroRuntimeNotInitialized = errors.New("wazero runtime not initialized") // ErrWazeroCompileFailed is returned when compiling WASM bytes fails. ErrWazeroCompileFailed = errors.New("wazero compile failed") // ErrWazeroInstantiateFailed is returned when instantiating a WASM module fails. ErrWazeroInstantiateFailed = errors.New("wazero instantiate failed") // ErrWazeroNoModuleLoaded is returned when Execute is called but no module // has been compiled yet. ErrWazeroNoModuleLoaded = errors.New("wazero no module loaded") // ErrWazeroFunctionNotFound is returned when CallFunction cannot find the // named exported function in the instantiated module. ErrWazeroFunctionNotFound = errors.New("wazero function not found") // ErrWazeroNotInstantiated is returned when CallFunction / GetGlobal is // called before any module has been instantiated via Execute. ErrWazeroNotInstantiated = errors.New("wazero module not instantiated") )
Sentinel errors returned by the Wazero engine.
Functions ¶
This section is empty.
Types ¶
This section is empty.