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