Macro gstd::export

source ·
macro_rules! export {
    ($f:ident -> $val:expr) => { ... };
}
Expand description

Create an FFI function that returns some data from the program as a fat pointer to the Wasm memory.

The value provided should have a to_string method (e.g., implement the Display trait).

It enables, for example, JS applications to get data from Wasm.

Examples

use gstd::export;

static mut VALUE: i32 = 0;

export!(my_function -> unsafe { VALUE });

#[no_mangle]
extern "C" fn init() {
    unsafe { VALUE = 42 };
}