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{})
| 126 | // |
| 127 | // Returns an error if shadowing is disabled and the name is already defined. |
| 128 | func (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 | // |