Function wasmer_c_api::wasm_c_api::module::wasm_module_exports [−][src]
#[no_mangle]pub unsafe extern "C" fn wasm_module_exports(
module: &wasm_module_t,
out: &mut wasm_exporttype_vec_t
)
Returns an array of the exported types in the module.
The order of the exports is guaranteed to be the same as in the WebAssembly bytecode.
Example
int main() { // Create the engine and the store. wasm_engine_t* engine = wasm_engine_new(); wasm_store_t* store = wasm_store_new(engine); // Create a WebAssembly module from a WAT definition. wasm_byte_vec_t wat; wasmer_byte_vec_new_from_string( &wat, "(module\n" " (func (export \"function\") (param i32 i64))\n" " (global (export \"global\") i32 (i32.const 7))\n" " (table (export \"table\") 0 funcref)\n" " (memory (export \"memory\") 1))" ); wasm_byte_vec_t wasm; wat2wasm(&wat, &wasm); // Create the module. wasm_module_t* module = wasm_module_new(store, &wasm); assert(module); // Extract the types exported by this module. wasm_exporttype_vec_t export_types; wasm_module_exports(module, &export_types); // We have 4 of them. assert(export_types.size == 4); // The first one is a function. Use // `wasm_externtype_as_functype_const` to continue to inspect the // type. { wasm_exporttype_t* export_type = export_types.data[0]; const wasm_name_t* export_name = wasm_exporttype_name(export_type); wasmer_assert_name(export_name, "function"); const wasm_externtype_t* extern_type = wasm_exporttype_type(export_type); assert(wasm_externtype_kind(extern_type) == WASM_EXTERN_FUNC); } // The second one is a global. Use // `wasm_externtype_as_globaltype_const` to continue to inspect the // type. { wasm_exporttype_t* export_type = export_types.data[1]; const wasm_name_t* export_name = wasm_exporttype_name(export_type); wasmer_assert_name(export_name, "global"); const wasm_externtype_t* extern_type = wasm_exporttype_type(export_type); assert(wasm_externtype_kind(extern_type) == WASM_EXTERN_GLOBAL); } // The third one is a table. Use // `wasm_externtype_as_tabletype_const` to continue to inspect the // type. { wasm_exporttype_t* export_type = export_types.data[2]; const wasm_name_t* export_name = wasm_exporttype_name(export_type); wasmer_assert_name(export_name, "table"); const wasm_externtype_t* extern_type = wasm_exporttype_type(export_type); assert(wasm_externtype_kind(extern_type) == WASM_EXTERN_TABLE); } // The fourth one is a memory. Use // `wasm_externtype_as_memorytype_const` to continue to inspect the // type. { wasm_exporttype_t* export_type = export_types.data[3]; const wasm_name_t* export_name = wasm_exporttype_name(export_type); wasmer_assert_name(export_name, "memory"); const wasm_externtype_t* extern_type = wasm_exporttype_type(export_type); assert(wasm_externtype_kind(extern_type) == WASM_EXTERN_MEMORY); } // Free everything. wasm_exporttype_vec_delete(&export_types); wasm_byte_vec_delete(&wasm); wasm_byte_vec_delete(&wat); wasm_module_delete(module); wasm_store_delete(store); wasm_engine_delete(engine); return 0; }