Files
wasmtime/crates/api/tests/invoke_func_via_table.rs
Alex Crichton e5afdd2ede Document the wasmtime::Instance APIs (#814)
* Document the `wasmtime::Instance` APIs

This documents oddities like the import list and export list and how to
match them all up. Addtionally this largely just expands all the docs
related to `Instance` to get filled out.

This also moves the `set_signal_handler` functions into
platform-specific modules in order to follow Rust idioms about how to
expose platform-specific information. Additionally the methods are
marked `unsafe` because I figure anything having to do with signal
handling is `unsafe` inherently. I don't actually know what these
functions do, so they're currently still undocumented.

* Fix build of python bindings

* Fix some rebase conflicts
2020-01-16 17:58:44 -06:00

34 lines
822 B
Rust

use anyhow::{Context as _, Result};
use wasmtime::*;
#[test]
fn test_invoke_func_via_table() -> Result<()> {
let store = Store::default();
let binary = wat::parse_str(
r#"
(module
(func $f (result i64) (i64.const 42))
(table (export "table") 1 1 anyfunc)
(elem (i32.const 0) $f)
)
"#,
)?;
let module = Module::new(&store, &binary).context("> Error compiling module!")?;
let instance = Instance::new(&module, &[]).context("> Error instantiating module!")?;
let f = instance
.get_export("table")
.unwrap()
.table()
.unwrap()
.get(0)
.funcref()
.unwrap()
.clone();
let result = f.call(&[]).unwrap();
assert_eq!(result[0].unwrap_i64(), 42);
Ok(())
}