* \brief Instantiates the module `m` with the provided `imports` * * \param cx the store in which to instantiate the provided module * \param m the module to instantiate * \param imports the list of imports to use to instantiate the module * * This `imports` parameter is expected to line up 1:1 with the imports * required by the `m`. The type of `m` can be inspected to determi
| 56 | * type, or if the wrong number of `imports` is provided. |
| 57 | */ |
| 58 | static TrapResult<Instance> create(Store::Context cx, const Module &m, |
| 59 | const std::vector<Extern> &imports) { |
| 60 | std::vector<wasmtime_extern_t> raw_imports; |
| 61 | for (const auto &item : imports) { |
| 62 | raw_imports.push_back(wasmtime_extern_t{}); |
| 63 | auto &last = raw_imports.back(); |
| 64 | detail::cvt_extern(item, last); |
| 65 | } |
| 66 | wasmtime_instance_t instance; |
| 67 | wasm_trap_t *trap = nullptr; |
| 68 | auto *error = wasmtime_instance_new(cx.ptr, m.capi(), raw_imports.data(), |
| 69 | raw_imports.size(), &instance, &trap); |
| 70 | if (error != nullptr) { |
| 71 | return TrapError(Error(error)); |
| 72 | } |
| 73 | if (trap != nullptr) { |
| 74 | return TrapError(Trap(trap)); |
| 75 | } |
| 76 | return Instance(instance); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * \brief Load an instance's export by name. |
nothing calls this directly
no test coverage detected