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

Function NewFunc

func.go:50–69  ·  view source on GitHub ↗

NewFunc creates a new `Func` with the given `ty` which, when called, will call `f` The `ty` given is the wasm type signature of the `Func` to create. When called the `f` callback receives two arguments. The first is a `Caller` to learn information about the calling context and the second is a list

(
	store Storelike,
	ty *FuncType,
	f func(*Caller, []Val) ([]Val, *Trap),
)

Source from the content-addressed store, hash-verified

48// If the `f` callback panics then the panic will be propagated to the caller
49// as well.
50func NewFunc(
51 store Storelike,
52 ty *FuncType,
53 f func(*Caller, []Val) ([]Val, *Trap),
54) *Func {
55 idx := insertFuncNew(getDataInStore(store), ty, f)
56
57 ret := C.wasmtime_func_t{}
58 C.go_func_new(
59 store.Context(),
60 ty.ptr(),
61 C.size_t(idx),
62 0,
63 &ret,
64 )
65 runtime.KeepAlive(store)
66 runtime.KeepAlive(ty)
67
68 return mkFunc(ret)
69}
70
71//export goTrampolineNew
72func goTrampolineNew(

Callers 9

TestFuncFunction · 0.85
TestFuncCallFunction · 0.85
TestFuncTrapFunction · 0.85
TestFuncPanicFunction · 0.85
TestFuncArgsFunction · 0.85
TestFuncOneRetFunction · 0.85
TestFuncWrongRetFunction · 0.85
TestFuncWrongRet2Function · 0.85
TestCallFuncFromCallerFunction · 0.85

Calls 5

insertFuncNewFunction · 0.85
getDataInStoreFunction · 0.85
mkFuncFunction · 0.85
ContextMethod · 0.65
ptrMethod · 0.45

Tested by 9

TestFuncFunction · 0.68
TestFuncCallFunction · 0.68
TestFuncTrapFunction · 0.68
TestFuncPanicFunction · 0.68
TestFuncArgsFunction · 0.68
TestFuncOneRetFunction · 0.68
TestFuncWrongRetFunction · 0.68
TestFuncWrongRet2Function · 0.68
TestCallFuncFromCallerFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…