| 147 | std::enable_if_t<WasmHostFunc<F>::Params::valid, bool> = true, |
| 148 | std::enable_if_t<WasmHostFunc<F>::Results::valid, bool> = true> |
| 149 | Result<std::monostate> func_wrap(std::string_view module, |
| 150 | std::string_view name, F &&f) { |
| 151 | using HostFunc = WasmHostFunc<F>; |
| 152 | auto params = HostFunc::Params::types(); |
| 153 | auto results = HostFunc::Results::types(); |
| 154 | auto ty = FuncType::from_iters(params, results); |
| 155 | auto *error = wasmtime_linker_define_func_unchecked( |
| 156 | ptr.get(), module.data(), module.length(), name.data(), name.length(), |
| 157 | ty.ptr.get(), Func::raw_callback_unchecked<std::remove_reference_t<F>>, |
| 158 | std::make_unique<std::remove_reference_t<F>>(std::forward<F>(f)) |
| 159 | .release(), |
| 160 | Func::raw_finalize<std::remove_reference_t<F>>); |
| 161 | |
| 162 | if (error != nullptr) { |
| 163 | return Error(error); |
| 164 | } |
| 165 | |
| 166 | return std::monostate(); |
| 167 | } |
| 168 | |
| 169 | /// Loads the "default" function, according to WASI commands and reactors, of |
| 170 | /// the module named `name` in this linker. |