Wasmtime
table.h File Reference
#include <wasm.h>
#include <wasmtime/error.h>
#include <wasmtime/extern.h>
#include <wasmtime/store.h>
#include <wasmtime/val.h>

Go to the source code of this file.

Functions

wasmtime_error_twasmtime_table_new (wasmtime_context_t *store, const wasm_tabletype_t *ty, const wasmtime_val_t *init, wasmtime_table_t *table)
 Creates a new host-defined wasm table. More...
 
wasm_tabletype_twasmtime_table_type (const wasmtime_context_t *store, const wasmtime_table_t *table)
 Returns the type of this table. More...
 
bool wasmtime_table_get (wasmtime_context_t *store, const wasmtime_table_t *table, uint64_t index, wasmtime_val_t *val)
 Gets a value in a table. More...
 
wasmtime_error_twasmtime_table_set (wasmtime_context_t *store, const wasmtime_table_t *table, uint64_t index, const wasmtime_val_t *value)
 Sets a value in a table. More...
 
uint64_t wasmtime_table_size (const wasmtime_context_t *store, const wasmtime_table_t *table)
 Returns the size, in elements, of the specified table.
 
wasmtime_error_twasmtime_table_grow (wasmtime_context_t *store, const wasmtime_table_t *table, uint64_t delta, const wasmtime_val_t *init, uint64_t *prev_size)
 Grows a table. More...
 

Detailed Description

Wasmtime APIs for interacting with WebAssembly tables.

Function Documentation

◆ wasmtime_table_get()

bool wasmtime_table_get ( wasmtime_context_t store,
const wasmtime_table_t table,
uint64_t  index,
wasmtime_val_t val 
)

Gets a value in a table.

Parameters
storethe store that owns table
tablethe table to access
indexthe table index to access
valwhere to store the table's value

This function will attempt to access a table element. If a nonzero value is returned then val is filled in and is owned by the caller. Otherwise zero is returned because the index is out-of-bounds.

◆ wasmtime_table_grow()

wasmtime_error_t * wasmtime_table_grow ( wasmtime_context_t store,
const wasmtime_table_t table,
uint64_t  delta,
const wasmtime_val_t init,
uint64_t *  prev_size 
)

Grows a table.

Parameters
storethe store that owns table
tablethe table to grow
deltathe number of elements to grow the table by
initthe initial value for new table element slots
prev_sizewhere to store the previous size of the table before growth

This function will attempt to grow the table by delta table elements. This can fail if delta would exceed the maximum size of the table or if init is the wrong type for this table. If growth is successful then NULL is returned and prev_size is filled in with the previous size of the table, in elements, before the growth happened.

This function does not take ownership of any of its arguments.

◆ wasmtime_table_new()

wasmtime_error_t * wasmtime_table_new ( wasmtime_context_t store,
const wasm_tabletype_t ty,
const wasmtime_val_t init,
wasmtime_table_t table 
)

Creates a new host-defined wasm table.

Parameters
storethe store to create the table within
tythe type of the table to create
initthe initial value for this table's elements
tablewhere to store the returned table

This function does not take ownership of any of its parameters, but yields ownership of returned error. This function may return an error if the init value does not match ty, for example.

◆ wasmtime_table_set()

wasmtime_error_t * wasmtime_table_set ( wasmtime_context_t store,
const wasmtime_table_t table,
uint64_t  index,
const wasmtime_val_t value 
)

Sets a value in a table.

Parameters
storethe store that owns table
tablethe table to write to
indexthe table index to write
valuethe value to store.

This function will store value into the specified index in the table. This does not take ownership of any argument but yields ownership of the error. This function can fail if value has the wrong type for the table, or if index is out of bounds.

◆ wasmtime_table_type()

wasm_tabletype_t * wasmtime_table_type ( const wasmtime_context_t store,
const wasmtime_table_t table 
)

Returns the type of this table.

The caller has ownership of the returned wasm_tabletype_t