Function wasmer_c_api::wasm_c_api::unstable::module::wasmer_module_set_name
source · #[no_mangle]
pub unsafe extern "C" fn wasmer_module_set_name(
module: &mut wasm_module_t,
name: &wasm_name_t
) -> bool
Expand description
Unstable non-standard Wasmer-specific API to set the module’s
name. The function returns true
if the name has been updated,
false
otherwise.
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)");
wasm_byte_vec_t wasm;
wat2wasm(&wat, &wasm);
// Create the module.
wasm_module_t* module = wasm_module_new(store, &wasm);
// Read the module's name. There is none for the moment.
{
wasm_name_t name;
wasmer_module_name(module, &name);
assert(name.size == 0);
}
// So, let's set a new name.
{
wasm_name_t name;
wasmer_byte_vec_new_from_string(&name, "hello");
wasmer_module_set_name(module, &name);
}
// And now, let's see the new name.
{
wasm_name_t name;
wasmer_module_name(module, &name);
// It works!
wasmer_assert_name(&name, "hello");
wasm_byte_vec_delete(&name);
}
// Free everything.
wasm_module_delete(module);
wasm_byte_vec_delete(&wasm);
wasm_byte_vec_delete(&wat);
wasm_store_delete(store);
wasm_engine_delete(engine);
return 0;
}