1b2c64de1SMangoPeachGrape /// \file wasmtime/component/instance.h
2b2c64de1SMangoPeachGrape 
3930d3543SMangoPeachGrape #ifndef WASMTIME_COMPONENT_INSTANCE_H
4930d3543SMangoPeachGrape #define WASMTIME_COMPONENT_INSTANCE_H
5930d3543SMangoPeachGrape 
6ce3c1a72SMangoPeachGrape #include <wasmtime/component/component.h>
7ce3c1a72SMangoPeachGrape #include <wasmtime/component/func.h>
8930d3543SMangoPeachGrape #include <wasmtime/conf.h>
9ce3c1a72SMangoPeachGrape #include <wasmtime/store.h>
10930d3543SMangoPeachGrape 
11930d3543SMangoPeachGrape #ifdef WASMTIME_FEATURE_COMPONENT_MODEL
12930d3543SMangoPeachGrape 
13930d3543SMangoPeachGrape #ifdef __cplusplus
14930d3543SMangoPeachGrape extern "C" {
15930d3543SMangoPeachGrape #endif
16930d3543SMangoPeachGrape 
17930d3543SMangoPeachGrape /// \brief Representation of a instance in Wasmtime.
18930d3543SMangoPeachGrape ///
19930d3543SMangoPeachGrape /// Instances are represented with a 64-bit identifying integer in Wasmtime.
20930d3543SMangoPeachGrape /// They do not have any destructor associated with them. Instances cannot
21930d3543SMangoPeachGrape /// interoperate between #wasmtime_store_t instances and if the wrong instance
22930d3543SMangoPeachGrape /// is passed to the wrong store then it may trigger an assertion to abort the
23930d3543SMangoPeachGrape /// process.
24930d3543SMangoPeachGrape typedef struct wasmtime_component_instance {
25930d3543SMangoPeachGrape   /// Internal identifier of what store this belongs to, never zero.
26930d3543SMangoPeachGrape   uint64_t store_id;
27930d3543SMangoPeachGrape   /// Internal index within the store.
28*5603ee7bSAlex Crichton   uint32_t __private;
29930d3543SMangoPeachGrape } wasmtime_component_instance_t;
30930d3543SMangoPeachGrape 
31ce3c1a72SMangoPeachGrape /**
32b2c64de1SMangoPeachGrape  * \brief A methods similar to #wasmtime_component_get_export_index except for
33b2c64de1SMangoPeachGrape  * this instance.
34ce3c1a72SMangoPeachGrape  *
35ce3c1a72SMangoPeachGrape  * \param instance the instance to look up \p name in
36ce3c1a72SMangoPeachGrape  * \param context the context where \p instance lives in
37ce3c1a72SMangoPeachGrape  * \param instance_export_index optional (i.e. nullable) instance to look up in
38ce3c1a72SMangoPeachGrape  * \param name the name of the export
39ce3c1a72SMangoPeachGrape  * \param name_len length of \p name in bytes
40ce3c1a72SMangoPeachGrape  * \return export index if found, else NULL
41ce3c1a72SMangoPeachGrape  */
42ce3c1a72SMangoPeachGrape WASM_API_EXTERN wasmtime_component_export_index_t *
43ce3c1a72SMangoPeachGrape wasmtime_component_instance_get_export_index(
44ce3c1a72SMangoPeachGrape     const wasmtime_component_instance_t *instance, wasmtime_context_t *context,
45ce3c1a72SMangoPeachGrape     const wasmtime_component_export_index_t *instance_export_index,
46ce3c1a72SMangoPeachGrape     const char *name, size_t name_len);
47ce3c1a72SMangoPeachGrape 
48ce3c1a72SMangoPeachGrape /**
49ce3c1a72SMangoPeachGrape  * \brief Looks up an exported function by name within this
50ce3c1a72SMangoPeachGrape  * #wasmtime_component_instance_t.
51ce3c1a72SMangoPeachGrape  *
52ce3c1a72SMangoPeachGrape  * \param instance the instance to look up this name in
53ce3c1a72SMangoPeachGrape  * \param context the store that \p instance lives in
54ce3c1a72SMangoPeachGrape  * \param export_index the export index of the function
55ce3c1a72SMangoPeachGrape  * \param func_out if found, the function corresponding to \p name
56ce3c1a72SMangoPeachGrape  * \return boolean marking if a function for \p name was found
57ce3c1a72SMangoPeachGrape  */
58ce3c1a72SMangoPeachGrape WASM_API_EXTERN bool wasmtime_component_instance_get_func(
59ce3c1a72SMangoPeachGrape     const wasmtime_component_instance_t *instance, wasmtime_context_t *context,
60ce3c1a72SMangoPeachGrape     const wasmtime_component_export_index_t *export_index,
61ce3c1a72SMangoPeachGrape     wasmtime_component_func_t *func_out);
62ce3c1a72SMangoPeachGrape 
63930d3543SMangoPeachGrape #ifdef __cplusplus
64930d3543SMangoPeachGrape } // extern "C"
65930d3543SMangoPeachGrape #endif
66930d3543SMangoPeachGrape 
67930d3543SMangoPeachGrape #endif // WASMTIME_FEATURE_COMPONENT_MODEL
68930d3543SMangoPeachGrape 
69930d3543SMangoPeachGrape #endif // WASMTIME_COMPONENT_INSTANCE_H
70