Skip to content

Instantly share code, notes, and snippets.

@kubkon
Created June 4, 2020 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kubkon/56ee4359fceeef469c9c0e58bf648292 to your computer and use it in GitHub Desktop.
Save kubkon/56ee4359fceeef469c9c0e58bf648292 to your computer and use it in GitHub Desktop.
Import globals and export func that uses them
(module
(type (;0;) (func (param i32)))
(type (;1;) (func))
(import "env" "frobinate" (func $frobinate (type 0)))
(import "env" "glob" (global (;0;) i32))
(export "foo" (func $foo))
(func $foo (type 1)
global.get 0
call $frobinate
return))
extern int glob;
extern void frobinate(int);
void foo() {
frobinate(glob);
}
#[link(wasm_import_module = "env")]
extern "C" {
static glob: u32;
fn frobinate(num: u32);
}
#[no_mangle]
pub unsafe extern "C" fn foo() {
frobinate(glob);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment