ztcl::wasm::host
Gives a WebAssembly module the import families of ztcl features, such as the Linux guests of ztcl::vm.
ztcl::wasm::host SUBCOMMAND ?ARG ...?
Description
A family is a set of imports with one wasm module name, for one feature of ztcl. The family vm gives a module the guests of ztcl::vm: create, start, exec, exit_code, output, status, stop, delete, snapshot, restore, and last_error. wit/host/vm.wit defines it.
Load the module with package require ztcl::wasm::host. A module gets a family only through the option -grant of instantiate, and a grant needs the capability of the feature, so a module never gets more than its host. Each import gives an i32: a result of 0 or more, or a negative error code, with the text in last_error. Each call checks each byte range against the memory of the module. Each import is a Tcl proc, so its calls use compute units of the interpreter.
The examples of this page run with --allow vm, and the setup makes the module $m, which imports vm.last_error and vm.start and exports them again.
Subcommands
| Subcommand | Description |
|---|---|
ztcl::wasm::host instantiate | Instantiates a module with the import families of a grant, and gives an instance handle. |
ztcl::wasm::host delete | Frees what each family made for the instances, and deletes them. |
ztcl::wasm::host families | Gives the names of the import families of the build. |
Returns
The result of the subcommand.
Examples
Each example of this page runs after
package require ztcl::wasm::host
# (import "vm" "last_error" (func (param i32 i32) (result i32))), (import "vm" "start" (func (param i32) (result i32))), (memory (export "memory") 1), and an export of each import
set m [ztcl::wasm new [binary decode hex 0061736d01000000010c0260027f7f017f60017f017f021c0202766d0a6c6173745f6572726f72000002766d05737461727400010503010001071f03066d656d6f727902000a6c6173745f6572726f7200000573746172740001]]
.
% ztcl::wasm::host families
vm info location motion audio
Errors
% ztcl::wasm::host bogus
unknown subcommand "bogus": must be delete, families, or instantiate
-errorcode TCL LOOKUP INDEX subcommand
% ztcl::wasm::host
wrong # args: should be "ztcl::wasm::host delete|families|instantiate ?arg ...?"
-errorcode TCL WRONGARGS
Facts
- Capability
- None.
- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztcl 1.0.0-beta.4
The full page: ztcl::wasm::host.