Description
Description
While working with Wasmtime's CLI, I discovered undocumented behavior differences between the two syntaxes for invoking WebAssembly functions:
wasmtime add.wasm --invoke add 1 2
(space syntax) - executes the function but doesn't display its return valuewasmtime --invoke=add add.wasm 1 2
(equals sign syntax) - executes the function AND displays its return value
Both commands show warnings that this functionality is experimental, but the CLI documentation doesn't explain this syntax difference or mention that return value display is only enabled with the equals sign variant.
Example
Using a simple WebAssembly module with an add
function that returns the sum of two integers:
(module
(func $add (param $lhs i32) (param $rhs i32) (result i32)
(i32.add
(local.get $lhs)
(local.get $rhs)
)
)
(export "add" (func $add))
)
Compiled with wat2wasm add.wat
, then:
# This command shows no return value
$ wasmtime add.wasm --invoke add 1 2
# This command shows '3' as the return value
$ wasmtime --invoke=add add.wasm 1 2
warning: using `--invoke` with a function that takes arguments is experimental and may break in the future
warning: using `--invoke` with a function that returns values is experimental and may break in the future
3
Suggested Documentation Improvement
I suggest updating the CLI documentation at https://docs.wasmtime.dev/cli-options.html to explain:
- The difference between space syntax (
--invoke function
) and equals sign syntax (--invoke=function
) - That function return values are only displayed with the equals sign syntax
- That this feature is experimental and may change in future versions
This would help new users understand the expected behavior and avoid confusion when trying to view function return values.
I noticed this while doing a course from Linux Foundation , since resource mentions the first way of executing command without equal sign - https://trainingportal.linuxfoundation.org/learn/course/webassembly-components-from-cloud-to-edge-lfd134/webassembly-from-scratch/exploring-webassembly?page=7
Additional Context
- Wasmtime version: 32.0.0 (the current version I'm using)
- OS: Linux Ubuntu (but should be consistent across platforms)