968: Added invoke option to the command r=syrusakbary a=syrusakbary

# Description 

This PR adds an `--invoke` to the Wasmer CLI

<!-- 
Provide details regarding the change including motivation,
links to related issues, and the context of the PR.
-->

# Review

- [x] Add a short description of the the change to the CHANGELOG.md file


Co-authored-by: Syrus <me@syrusakbary.com>
This commit is contained in:
bors[bot]
2019-11-15 22:06:35 +00:00
committed by GitHub
2 changed files with 10 additions and 1 deletions

View File

@ -2,6 +2,7 @@
## **[Unreleased]**
- [#968](https://github.com/wasmerio/wasmer/pull/968) Added `--invoke` option to the command
- [#960](https://github.com/wasmerio/wasmer/pull/960) Fix `runtime-c-api` header files when compiled by clang.
- [#925](https://github.com/wasmerio/wasmer/pull/925) Host functions can be closures with a captured environment.
- [#917](https://github.com/wasmerio/wasmer/pull/917) Host functions (aka imported functions) may not have `&mut vm::Ctx` as first argument, i.e. the presence of the `&mut vm::Ctx` argument is optional.

View File

@ -132,6 +132,10 @@ struct Run {
)]
backend: Backend,
/// Invoke a specified function
#[structopt(long = "invoke", short = "i")]
invoke: Option<String>,
/// Emscripten symbol map
#[structopt(long = "em-symbol-map", parse(from_os_str), group = "emscripten")]
em_symbol_map: Option<PathBuf>,
@ -683,8 +687,12 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
args.push(Value::I32(x));
}
let invoke_fn = match options.invoke.as_ref() {
Some(fun) => fun,
_ => "main",
};
instance
.dyn_func("main")
.dyn_func(&invoke_fn)
.map_err(|e| format!("{:?}", e))?
.call(&args)
.map_err(|e| format!("{:?}", e))?;