invoke-witc
Add the crate to the dependencies.
invoke-witc = "0.2"
The usage of this crate is using the following macros to generate polyfill programs. e.g.
wit_instance!;
wit_runtime!;
wit_runtime!;
Let's assume there has a file xxx.wit contains
num : func(a: u32) -> u32
and discuss some special cases
import: instance vs runtime
In instance, if we write
wit_instance!;
then we can just use num(10) to get a u32. But in runtime, due to the limitation, we will have to write
let u = num;
where vm : Vm.
export in runtime: with & without name
Let's say we are exporting component xxx in runtime, we will need to provide definition of num, like the following.
wit_runtime!;
// An example implementation
Then we have to register import object to vm : Vm, therefore, we will write
vm.register_import_module?
to ensure later wasm instances can use this implementation. A notable thing is that you can define export name:
invoke_witc::wit_runtime!(export(a = "./xxx.wit"));
invoke_witc::wit_runtime!(export(b = "./yyy.wit"));
with export name, the wit_import_object will be wrapped under different module, and hence, we will have:
vm.register_import_module?
.register_import_module?