Skip to content

Instantly share code, notes, and snippets.

@alexcrichton
Created June 25, 2020 20:30
Show Gist options
  • Save alexcrichton/a0b81f6e2cf3d5c863d6a0a4542d207c to your computer and use it in GitHub Desktop.
Save alexcrichton/a0b81f6e2cf3d5c863d6a0a4542d207c to your computer and use it in GitHub Desktop.
use wasmtime::*;
struct A {
table: Table,
a: i32,
}
impl Drop for A {
fn drop(&mut self) {
let me = self.table.get(0).unwrap();
println!("{:?}", me);
println!("{}", self.a);
}
}
fn main() {
let mut config = Config::new();
config.wasm_reference_types(true);
let engine = Engine::new(&config);
let store = Store::new(&engine);
let module = Module::new(
store.engine(),
r#"
(module
(table (export "t") 1 externref)
(func (export "foo") (param externref)
i32.const 0
local.get 0
table.set)
)
"#,
)
.unwrap();
let instance = Instance::new(&store, &module, &[]).unwrap();
let foo = instance.get_func("foo").unwrap();
let me = ExternRef::new(
&store,
A {
a: 0,
table: instance.get_table("t").unwrap(),
},
);
foo.call(&[me.into()]).unwrap();
store.gc();
foo.call(&[Val::ExternRef(None)]).unwrap();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment