The PageSize constant defines the size of WebAssembly memory pages in bytes.
See https://www.w3.org/TR/2019/REC-wasm-core-1-20191205/#page-size
const PageSize = 65536
Function is an implementation of the api.Function interface, it represents a function in a WebAssembly module.
Until accessed through a Module's method, the function definition's ModuleName method returns an empty string and its Index method returns 0.
type Function struct { internalapi.WazeroOnlyType // GoModuleFunction may be set to a non-nil value to allow calling of the // function via Call or CallWithStack. // // It is the user's responsibility to ensure that the signature of this // implementation matches the ParamTypes and ResultTypes fields. GoModuleFunction api.GoModuleFunction // Type lists representing the function signature. Those fields should be // set for the function to be properly constructed. The Function's Call // and CallWithStack methods will error if those fields are nil. ParamTypes []api.ValueType ResultTypes []api.ValueType // Sets of names associated with the function. It is valid to leave those // names empty, they are only used for debugging purposes. FunctionName string DebugName string ParamNames []string ResultNames []string ExportNames []string // contains filtered or unexported fields }
func NewFunction(fn any) *Function
NewFunction constructs a Function object from a Go function.
The function fn must accept at least two arguments of type context.Context and api.Module. Any other arguments and return values must be of type uint32, uint64, int32, int64, float32, or float64. The call panics if fn is not a Go functionn or has an unsupported signature.
func (f *Function) Call(ctx context.Context, params ...uint64) ([]uint64, error)
func (f *Function) CallWithStack(ctx context.Context, stack []uint64) error
func (f *Function) Definition() api.FunctionDefinition
Global is an implementation of the api.Global interface, it represents a global in a WebAssembly module.
type Global struct { internalapi.WazeroOnlyType // Type of the global value, used to interpret bits of the Value field. ValueType api.ValueType // Value of the global packed in a 64 bits field. Value uint64 // List of names that the globla is exported as. ExportNames []string }
func GlobalF32(value float32, export ...string) *Global
func GlobalF64(value float64, export ...string) *Global
func GlobalI32(value int32, export ...string) *Global
func GlobalI64(value int64, export ...string) *Global
func (g *Global) Get() uint64
func (g *Global) String() string
func (g *Global) Type() api.ValueType
Memory is an implementation of the api.Memory interface, representing the memory of a WebAssembly module.
type Memory struct { internalapi.WazeroOnlyType // Byte slices holding the memory pages. // // It is the user's repsonsibility to ensure that the length of this byte // slice is a multiple of the page size. Bytes []byte // Min and max number of memory pages which may be held in this memory. // // Leaving Max to zero means no upper bound. Min uint32 Max uint32 // contains filtered or unexported fields }
func NewFixedMemory(size int) *Memory
NewFixedMemory constructs a Memory object of the given size. The returned memory is configured with a max limit to prevent growing beyond its initial size.
func NewMemory(size int) *Memory
NewMemory constructs a Memory object with a buffer of the given size, aligned to the closest multiple of the page size.
func (m *Memory) Definition() api.MemoryDefinition
func (m *Memory) Grow(deltaPages uint32) (previousPages uint32, ok bool)
func (m *Memory) Read(offset, length uint32) ([]byte, bool)
func (m *Memory) ReadByte(offset uint32) (byte, bool)
func (m *Memory) ReadFloat32Le(offset uint32) (float32, bool)
func (m *Memory) ReadFloat64Le(offset uint32) (float64, bool)
func (m *Memory) ReadUint16Le(offset uint32) (uint16, bool)
func (m *Memory) ReadUint32Le(offset uint32) (uint32, bool)
func (m *Memory) ReadUint64Le(offset uint32) (uint64, bool)
func (m *Memory) Size() uint32
func (m *Memory) Write(offset uint32, value []byte) bool
func (m *Memory) WriteByte(offset uint32, value byte) bool
func (m *Memory) WriteFloat32Le(offset uint32, value float32) bool
func (m *Memory) WriteFloat64Le(offset uint32, value float64) bool
func (m *Memory) WriteString(offset uint32, value string) bool
func (m *Memory) WriteUint16Le(offset uint32, value uint16) bool
func (m *Memory) WriteUint32Le(offset uint32, value uint32) bool
func (m *Memory) WriteUint64Le(offset uint32, value uint64) bool
Module is an implementation of the api.Module interface, it represents a WebAssembly module.
type Module struct { internalapi.WazeroOnlyType // The module name that will be returned by calling the Name method. ModuleName string // The list of functions of the module. Functions with a non-empty export // names will be exported by the module. Functions []*Function // The list of globals of the module. Global Globals []*Global // The program memory. If non-nil, the memory is automatically exported as // "memory". ExportMemory *Memory // contains filtered or unexported fields }
func NewModule(memory *Memory, functions ...*Function) *Module
NewModule constructs a Module object with the given memory and function list.
func (m *Module) Close(ctx context.Context) error
Close implements the same method as documented on api.Closer.
func (m *Module) CloseWithExitCode(ctx context.Context, exitCode uint32) error
CloseWithExitCode implements the same method as documented on api.Closer.
func (m *Module) ExitStatus() (exitCode uint32, exited bool)
func (m *Module) ExportedFunction(name string) api.Function
ExportedFunction implements the same method as documented on api.Module.
func (m *Module) ExportedFunctionDefinitions() map[string]api.FunctionDefinition
ExportedFunctionDefinitions implements the same method as documented on api.Module.
func (m *Module) ExportedGlobal(name string) api.Global
ExportedGlobal implements the same method as documented on api.Module.
func (m *Module) ExportedMemory(name string) api.Memory
ExportedMemory implements the same method as documented on api.Module.
func (m *Module) ExportedMemoryDefinitions() map[string]api.MemoryDefinition
ExportedMemoryDefinitions implements the same method as documented on api.Module.
func (m *Module) Function(i int) api.Function
func (m *Module) Global(i int) api.Global
Global implements the same method as documented on experimental.InternalModule.
func (m *Module) IsClosed() bool
IsClosed implements the same method as documented on api.Module.
func (m *Module) Memory() api.Memory
Memory implements the same method as documented on api.Module.
func (m *Module) Name() string
Name implements the same method as documented on api.Module.
func (m *Module) NumFunction() int
func (m *Module) NumGlobal() int
NumGlobal implements the same method as documented on experimental.InternalModule.
func (m *Module) String() string
String implements fmt.Stringer.