1 /** 2 * \file wasmtime/table.h 3 * 4 * Wasmtime APIs for interacting with WebAssembly tables. 5 */ 6 7 #ifndef WASMTIME_TABLE_H 8 #define WASMTIME_TABLE_H 9 10 #include <wasm.h> 11 #include <wasmtime/error.h> 12 #include <wasmtime/extern.h> 13 #include <wasmtime/store.h> 14 #include <wasmtime/val.h> 15 16 #ifdef __cplusplus 17 extern "C" { 18 #endif 19 20 /** 21 * \brief Creates a new host-defined wasm table. 22 * 23 * \param store the store to create the table within 24 * \param ty the type of the table to create 25 * \param init the initial value for this table's elements 26 * \param table where to store the returned table 27 * 28 * This function does not take ownership of any of its parameters, but yields 29 * ownership of returned error. This function may return an error if the `init` 30 * value does not match `ty`, for example. 31 */ 32 WASM_API_EXTERN wasmtime_error_t *wasmtime_table_new(wasmtime_context_t *store, 33 const wasm_tabletype_t *ty, 34 const wasmtime_val_t *init, 35 wasmtime_table_t *table); 36 37 /** 38 * \brief Returns the type of this table. 39 * 40 * The caller has ownership of the returned #wasm_tabletype_t 41 */ 42 WASM_API_EXTERN wasm_tabletype_t * 43 wasmtime_table_type(const wasmtime_context_t *store, 44 const wasmtime_table_t *table); 45 46 /** 47 * \brief Gets a value in a table. 48 * 49 * \param store the store that owns `table` 50 * \param table the table to access 51 * \param index the table index to access 52 * \param val where to store the table's value 53 * 54 * This function will attempt to access a table element. If a nonzero value is 55 * returned then `val` is filled in and is owned by the caller. Otherwise zero 56 * is returned because the `index` is out-of-bounds. 57 */ 58 WASM_API_EXTERN bool wasmtime_table_get(wasmtime_context_t *store, 59 const wasmtime_table_t *table, 60 uint64_t index, wasmtime_val_t *val); 61 62 /** 63 * \brief Sets a value in a table. 64 * 65 * \param store the store that owns `table` 66 * \param table the table to write to 67 * \param index the table index to write 68 * \param value the value to store. 69 * 70 * This function will store `value` into the specified index in the table. This 71 * does not take ownership of any argument but yields ownership of the error. 72 * This function can fail if `value` has the wrong type for the table, or if 73 * `index` is out of bounds. 74 */ 75 WASM_API_EXTERN wasmtime_error_t * 76 wasmtime_table_set(wasmtime_context_t *store, const wasmtime_table_t *table, 77 uint64_t index, const wasmtime_val_t *value); 78 79 /** 80 * \brief Returns the size, in elements, of the specified table 81 */ 82 WASM_API_EXTERN uint64_t wasmtime_table_size(const wasmtime_context_t *store, 83 const wasmtime_table_t *table); 84 85 /** 86 * \brief Grows a table. 87 * 88 * \param store the store that owns `table` 89 * \param table the table to grow 90 * \param delta the number of elements to grow the table by 91 * \param init the initial value for new table element slots 92 * \param prev_size where to store the previous size of the table before growth 93 * 94 * This function will attempt to grow the table by `delta` table elements. This 95 * can fail if `delta` would exceed the maximum size of the table or if `init` 96 * is the wrong type for this table. If growth is successful then `NULL` is 97 * returned and `prev_size` is filled in with the previous size of the table, in 98 * elements, before the growth happened. 99 * 100 * This function does not take ownership of any of its arguments. 101 */ 102 WASM_API_EXTERN wasmtime_error_t * 103 wasmtime_table_grow(wasmtime_context_t *store, const wasmtime_table_t *table, 104 uint64_t delta, const wasmtime_val_t *init, 105 uint64_t *prev_size); 106 107 #ifdef __cplusplus 108 } // extern "C" 109 #endif 110 111 #endif // WASMTIME_TABLE_H 112