Skip to content

Instantly share code, notes, and snippets.

@tshemsedinov
Created August 7, 2023 20:12
Show Gist options
  • Save tshemsedinov/c807de6b001133767577352562c0c9f7 to your computer and use it in GitHub Desktop.
Save tshemsedinov/c807de6b001133767577352562c0c9f7 to your computer and use it in GitHub Desktop.
Rust compiled by wasm-pack
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
extern {
pub fn callback(res: i32);
}
#[wasm_bindgen]
pub fn add(a: i32, b: i32) -> i32 {
return a + b;
}
#[wasm_bindgen]
pub fn add_callback(a: i32, b: i32) {
callback(a + b)
}
(module
(type (;0;) (func (param i32)))
(type (;1;) (func (param i32 i32)))
(type (;2;) (func (param i32 i32) (result i32)))
(import "wbg" "__wbg_callback_330497ee23f1aa0e" (func (;0;) (type 0)))
(func (;1;) (type 1) (param i32 i32)
local.get 0
local.get 1
i32.add
call 0)
(func (;2;) (type 2) (param i32 i32) (result i32)
local.get 0
local.get 1
i32.add)
(memory (;0;) 17)
(export "memory" (memory 0))
(export "add" (func 2))
(export "add_callback" (func 1)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment