MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime-go / FuncWrap

Method FuncWrap

linker.go:128–151  ·  view source on GitHub ↗

FuncWrap defines a function in this linker in the same style as `WrapFunc` Note that this function does not require a `Storelike`, which is intentional. This function can be used to insert store-independent functions into this linker which allows this linker to be used for instantiating modules in

(module, name string, f interface{})

Source from the content-addressed store, hash-verified

126//
127// Returns an error if shadowing is disabled and the name is already defined.
128func (l *Linker) FuncWrap(module, name string, f interface{}) error {
129 val := reflect.ValueOf(f)
130 ty := inferFuncType(val)
131 idx := insertFuncWrap(nil, val)
132 err := C.go_linker_define_func(
133 l.ptr(),
134 C._GoStringPtr(module),
135 C._GoStringLen(module),
136 C._GoStringPtr(name),
137 C._GoStringLen(name),
138 ty.ptr(),
139 1, // this is "wrap"
140 C.size_t(idx),
141 )
142 runtime.KeepAlive(l)
143 runtime.KeepAlive(module)
144 runtime.KeepAlive(name)
145 runtime.KeepAlive(ty)
146 if err == nil {
147 return nil
148 }
149
150 return mkError(err)
151}
152
153// DefineInstance defines all exports of an instance provided under the module name provided.
154//

Calls 4

ptrMethod · 0.95
inferFuncTypeFunction · 0.85
insertFuncWrapFunction · 0.85
mkErrorFunction · 0.85