Wasmtime
component/types/instance.hh
Go to the documentation of this file.
1
5#ifndef WASMTIME_COMPONENT_TYPES_INSTANCE_HH
6#define WASMTIME_COMPONENT_TYPES_INSTANCE_HH
7
8#include <wasmtime/conf.h>
9
10#ifdef WASMTIME_FEATURE_COMPONENT_MODEL
11
12#include <memory>
13#include <optional>
14#include <string>
16#include <wasmtime/engine.hh>
17#include <wasmtime/helpers.hh>
18
19namespace wasmtime {
20namespace component {
21
22class ComponentExtern;
23
28 WASMTIME_CLONE_WRAPPER(ComponentInstanceType,
29 wasmtime_component_instance_type);
30
32 size_t export_count(const Engine &engine) const {
33 return wasmtime_component_instance_type_export_count(capi(), engine.capi());
34 }
35
40 std::optional<ComponentExtern> export_get(const Engine &engine,
41 std::string_view name) const;
42
47 std::optional<std::pair<std::string_view, ComponentExtern>>
48 export_nth(const Engine &engine, size_t nth) const;
49};
50
51} // namespace component
52} // namespace wasmtime
53
55
56inline std::optional<wasmtime::component::ComponentExtern>
57wasmtime::component::ComponentInstanceType::export_get(
58 const wasmtime::Engine &engine, std::string_view name) const {
61 capi(), engine.capi(), name.data(), name.size(), &e);
62 if (!found) {
63 return std::nullopt;
64 }
66}
67
68inline std::optional<
69 std::pair<std::string_view, wasmtime::component::ComponentExtern>>
70wasmtime::component::ComponentInstanceType::export_nth(
71 const wasmtime::Engine &engine, size_t nth) const {
73 const char *name_data;
74 size_t name_size;
76 capi(), engine.capi(), nth, &name_data, &name_size, &e);
77 if (!found) {
78 return std::nullopt;
79 }
80 return std::make_pair(std::string_view(name_data, name_size),
82}
83
84#endif // WASMTIME_FEATURE_COMPONENT_MODEL
85
86#endif // WASMTIME_COMPONENT_TYPES_INSTANCE_HH
Global compilation state in Wasmtime.
Definition: engine.hh:22
Full description of a single import or export of a component or a component instance.
Definition: component/types/component.hh:198
Represents the type of a component instance.
Definition: component/types/instance.hh:27
struct wasmtime_component_extern_t wasmtime_component_extern_t
Full description of a single component or component instance export or import.
Definition: component/types/component.h:166
WASM_API_EXTERN bool wasmtime_component_instance_type_export_nth(const wasmtime_component_instance_type_t *ty, const wasm_engine_t *engine, size_t nth, const char **name_ret, size_t *name_len_ret, struct wasmtime_component_extern_t **ret)
Retrieves the nth export.
WASM_API_EXTERN bool wasmtime_component_instance_type_export_get(const wasmtime_component_instance_type_t *ty, const wasm_engine_t *engine, const char *name, size_t name_len, struct wasmtime_component_extern_t **ret)
Retrieves the export with the specified name.
WASM_API_EXTERN size_t wasmtime_component_instance_type_export_count(const wasmtime_component_instance_type_t *ty, const wasm_engine_t *engine)
Returns the number of exports of a component instance type.
Build-time defines for how the C API was built.