Skip to content

Commit

Permalink
Merge #968
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
bors[bot] and syrusakbary authored Nov 15, 2019
2 parents c15b9fc + 3d36360 commit 182e53b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 9 additions & 1 deletion src/bin/wasmer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down Expand Up @@ -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))?;
Expand Down

0 comments on commit 182e53b

Please sign in to comment.