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

Method FuncNew

linker.go:97–118  ·  view source on GitHub ↗

FuncNew defines a function in this linker in the same style as `NewFunc` 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 mu

(module, name string, ty *FuncType, f func(*Caller, []Val) ([]Val, *Trap))

Source from the content-addressed store, hash-verified

95//
96// Returns an error if shadowing is disabled and the name is already defined.
97func (l *Linker) FuncNew(module, name string, ty *FuncType, f func(*Caller, []Val) ([]Val, *Trap)) error {
98 idx := insertFuncNew(nil, ty, f)
99 err := C.go_linker_define_func(
100 l.ptr(),
101 C._GoStringPtr(module),
102 C._GoStringLen(module),
103 C._GoStringPtr(name),
104 C._GoStringLen(name),
105 ty.ptr(),
106 0, // this is "new"
107 C.size_t(idx),
108 )
109 runtime.KeepAlive(l)
110 runtime.KeepAlive(module)
111 runtime.KeepAlive(name)
112 runtime.KeepAlive(ty)
113 if err == nil {
114 return nil
115 }
116
117 return mkError(err)
118}
119
120// FuncWrap defines a function in this linker in the same style as `WrapFunc`
121//

Callers 1

TestLinkerFuncsFunction · 0.95

Calls 3

ptrMethod · 0.95
insertFuncNewFunction · 0.85
mkErrorFunction · 0.85

Tested by 1

TestLinkerFuncsFunction · 0.76