Documentation ¶
Index ¶
- Variables
- type AdvancedFunc
- type Instance
- type Linker
- func (l *Linker) Define(modName string, mod *Module)
- func (l *Linker) DefineAdvancedFunc(modName, funcName string, funcGenerator AdvancedFunc) error
- func (l *Linker) DefineFunc(modName, funcName string, f interface{}) error
- func (l *Linker) DefineGlobal(modName, globalName string, global interface{}) error
- func (l *Linker) DefineMemory(modName, memName string, mem []byte) error
- func (l *Linker) DefineTable(modName, tableName string, table []*uint32) error
- func (l *Linker) Instantiate(mainModule *Module) (*Instance, error)
- type Module
Constants ¶
This section is empty.
Variables ¶
var (
ErrInvalidSign = errors.New("invalid signature")
)
errors on linking modules
Functions ¶
This section is empty.
Types ¶
type AdvancedFunc ¶
type AdvancedFunc func(ins *Instance) interface{}
AdvancedFunc is a advanced host func comparing to normal go host func Dev will be able to handle the pre/post-call process of the func and manipulate the Instance's fields like memory
e.g. when we wanna add toll after calling the host func f
func ExampleFuncGenerator_addToll() { var linker = wasman.NewLinker() var f = func() {fmt.Println("wasm")} var af = wasman.AdvancedFunc(func(ins *wasman.Instance) interface{} { return func() { f() ins.AddGas(11) } }) linker.DefineAdvancedFunc("env", "add_gas", af) }
e.g. when we wanna manipulate memory
func ExampleFuncGenerator_addToll() { var linker = wasman.NewLinker() var af = wasman.AdvancedFunc(func(ins *wasman.Instance) interface{} { return func(ptr uint32, length uint32) { msg := ins.Memory[int(ptr), int(ptr+uint32)] fmt.Println(b) } }) linker.DefineAdvancedFunc("env", "print_msg", af) }
type Linker ¶
type Linker struct { config.LinkerConfig Modules map[string]*Module // the built-in modules which acts as externs when instantiating coming main module }
Linker is a helper to instantiate new modules
func NewLinkerWithModuleMap ¶
func NewLinkerWithModuleMap(config config.LinkerConfig, in map[string]*Module) *Linker
NewLinkerWithModuleMap creates a new Linker with the built-in modules
func (*Linker) DefineAdvancedFunc ¶
func (l *Linker) DefineAdvancedFunc(modName, funcName string, funcGenerator AdvancedFunc) error
DefineAdvancedFunc will define a AdvancedFunc on linker
func (*Linker) DefineFunc ¶
DefineFunc puts a simple go style func into Linker's modules. This f should be a simply func which doesnt handle ins's fields.
func (*Linker) DefineGlobal ¶
DefineGlobal will defined an external global for the main module
func (*Linker) DefineMemory ¶
DefineMemory will defined an external memory for the main module
func (*Linker) DefineTable ¶
DefineTable will defined an external table for the main module