You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
741 B
30 lines
741 B
use anyhow::{Context as _, Result};
|
|
use wasmtime::*;
|
|
|
|
#[test]
|
|
fn test_invoke_func_via_table() -> Result<()> {
|
|
let store = Store::default();
|
|
|
|
let wat = 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, wat).context("> Error compiling module!")?;
|
|
let instance = Instance::new(&module, &[]).context("> Error instantiating module!")?;
|
|
|
|
let f = instance
|
|
.get_table("table")
|
|
.unwrap()
|
|
.get(0)
|
|
.unwrap()
|
|
.funcref()
|
|
.unwrap()
|
|
.clone();
|
|
let result = f.call(&[]).unwrap();
|
|
assert_eq!(result[0].unwrap_i64(), 42);
|
|
Ok(())
|
|
}
|
|
|