Wasmtime
component/instance.hh
Go to the documentation of this file.
1
2
3#ifndef WASMTIME_COMPONENT_INSTANCE_HH
4#define WASMTIME_COMPONENT_INSTANCE_HH
5
6#include <wasmtime/conf.h>
7
8#ifdef WASMTIME_FEATURE_COMPONENT_MODEL
9
10#include <string_view>
14#include <wasmtime/store.hh>
15
16namespace wasmtime {
17namespace component {
18
22class Instance {
24
25public:
28 : instance(inst) {}
29
37 std::optional<ExportIndex> get_export_index(Store::Context cx,
38 const ExportIndex *instance,
39 std::string_view name) const {
42 &this->instance, cx.capi(), instance ? instance->capi() : nullptr,
43 name.data(), name.size());
44 if (ret == nullptr) {
45 return std::nullopt;
46 }
47 return ExportIndex(ret);
48 }
49
51 std::optional<Func> get_func(Store::Context cx,
52 const ExportIndex &index) const {
54 bool found = wasmtime_component_instance_get_func(&instance, cx.capi(),
55 index.capi(), &ret);
56 if (!found)
57 return std::nullopt;
58 return Func(ret);
59 }
60
62 const wasmtime_component_instance_t *capi() const { return &instance; }
63};
64
65} // namespace component
66} // namespace wasmtime
67
68#endif // WASMTIME_FEATURE_COMPONENT_MODEL
69
70#endif // WASMTIME_COMPONENT_INSTANCE_H
An interior pointer into a Store.
Definition: store.hh:60
const wasmtime_context_t * capi() const
Returns the underlying C API pointer.
Definition: store.hh:154
An index to an exported item within a particular component.
Definition: component/component.hh:31
const wasmtime_component_export_index_t * capi() const
Returns the underlying C API pointer.
Definition: component/component.hh:62
Class representing an instantiated WebAssembly component.
Definition: component/func.hh:23
Class representing an instantiated WebAssembly component.
Definition: component/instance.hh:22
std::optional< Func > get_func(Store::Context cx, const ExportIndex &index) const
Looks up an exported function by its export index.
Definition: component/instance.hh:51
std::optional< ExportIndex > get_export_index(Store::Context cx, const ExportIndex *instance, std::string_view name) const
Looks up an exported item from this instance by name, returning the index at which it can be found.
Definition: component/instance.hh:37
Instance(const wasmtime_component_instance_t &inst)
Constructs an Instance from the underlying C API struct.
Definition: component/instance.hh:27
const wasmtime_component_instance_t * capi() const
Returns the underlying C API pointer.
Definition: component/instance.hh:62
struct wasmtime_component_export_index_t wasmtime_component_export_index_t
A value which represents a known export of a component.
Definition: component/component.h:113
wasmtime_component_export_index_t * wasmtime_component_instance_get_export_index(const wasmtime_component_instance_t *instance, wasmtime_context_t *context, const wasmtime_component_export_index_t *instance_export_index, const char *name, size_t name_len)
A methods similar to wasmtime_component_get_export_index except for this instance.
bool wasmtime_component_instance_get_func(const wasmtime_component_instance_t *instance, wasmtime_context_t *context, const wasmtime_component_export_index_t *export_index, wasmtime_component_func_t *func_out)
Looks up an exported function by name within this wasmtime_component_instance_t.
Build-time defines for how the C API was built.
Representation of a function in Wasmtime.
Definition: component/func.h:24
Representation of a instance in Wasmtime.
Definition: component/instance.h:24