1 #ifndef WASMTIME_COMPONENT_INSTANCE_H
2 #define WASMTIME_COMPONENT_INSTANCE_H
3 
4 #include <wasmtime/component/component.h>
5 #include <wasmtime/component/func.h>
6 #include <wasmtime/conf.h>
7 #include <wasmtime/store.h>
8 
9 #ifdef WASMTIME_FEATURE_COMPONENT_MODEL
10 
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14 
15 /// \brief Representation of a instance in Wasmtime.
16 ///
17 /// Instances are represented with a 64-bit identifying integer in Wasmtime.
18 /// They do not have any destructor associated with them. Instances cannot
19 /// interoperate between #wasmtime_store_t instances and if the wrong instance
20 /// is passed to the wrong store then it may trigger an assertion to abort the
21 /// process.
22 typedef struct wasmtime_component_instance {
23   /// Internal identifier of what store this belongs to, never zero.
24   uint64_t store_id;
25   /// Internal index within the store.
26   size_t index;
27 } wasmtime_component_instance_t;
28 
29 /**
30  * \brief A methods similar to \fn wasmtime_component_get_export_index() except
31  * for this instance.
32  *
33  * \param instance the instance to look up \p name in
34  * \param context the context where \p instance lives in
35  * \param instance_export_index optional (i.e. nullable) instance to look up in
36  * \param name the name of the export
37  * \param name_len length of \p name in bytes
38  * \return export index if found, else NULL
39  */
40 WASM_API_EXTERN wasmtime_component_export_index_t *
41 wasmtime_component_instance_get_export_index(
42     const wasmtime_component_instance_t *instance, wasmtime_context_t *context,
43     const wasmtime_component_export_index_t *instance_export_index,
44     const char *name, size_t name_len);
45 
46 /**
47  * \brief Looks up an exported function by name within this
48  * #wasmtime_component_instance_t.
49  *
50  * \param instance the instance to look up this name in
51  * \param context the store that \p instance lives in
52  * \param export_index the export index of the function
53  * \param func_out if found, the function corresponding to \p name
54  * \return boolean marking if a function for \p name was found
55  */
56 WASM_API_EXTERN bool wasmtime_component_instance_get_func(
57     const wasmtime_component_instance_t *instance, wasmtime_context_t *context,
58     const wasmtime_component_export_index_t *export_index,
59     wasmtime_component_func_t *func_out);
60 
61 #ifdef __cplusplus
62 } // extern "C"
63 #endif
64 
65 #endif // WASMTIME_FEATURE_COMPONENT_MODEL
66 
67 #endif // WASMTIME_COMPONENT_INSTANCE_H
68