diff options
| author | Henry Gressmann <mail@henrygressmann.de> | 2024-01-26 01:26:09 +0100 |
|---|---|---|
| committer | Henry Gressmann <mail@henrygressmann.de> | 2024-01-26 01:26:09 +0100 |
| commit | 461126ce309f99e4ad2a6ddcbc175ea01c5e8fee (patch) | |
| tree | 30de8bcfec97f87d468191fb9959f90e7ee91100 /examples/wasm-rust.rs | |
| parent | b9a4e8788f374dac94e4f3f5b062dbe2a1d2a10c (diff) | |
feat: full no_std support
Signed-off-by: Henry Gressmann <mail@henrygressmann.de>
Diffstat (limited to 'examples/wasm-rust.rs')
| -rw-r--r-- | examples/wasm-rust.rs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/examples/wasm-rust.rs b/examples/wasm-rust.rs new file mode 100644 index 0000000..21d3eb8 --- /dev/null +++ b/examples/wasm-rust.rs @@ -0,0 +1,41 @@ +use color_eyre::eyre::Result; +use tinywasm::{Extern, FuncContext, Imports, Module, Store}; + +fn main() -> Result<()> { + let args = std::env::args().collect::<Vec<_>>(); + if args.len() < 2 { + println!("Usage: cargo run --example wasm-rust <rust_example>"); + println!("Available examples:"); + println!(" hello"); + return Ok(()); + } + + match args[1].as_str() { + "hello" => hello()?, + _ => {} + } + + Ok(()) +} + +fn hello() -> Result<()> { + // const HELLO_WASM: &[u8] = include_bytes!("./rust/out/hello.wasm"); + // let module = Module::parse_bytes(&HELLO_WASM)?; + // let mut store = Store::default(); + + // let mut imports = Imports::new(); + // imports.define( + // "env", + // "printi32", + // Extern::typed_func(|_: FuncContext<'_>, x: i32| { + // println!("{}", x); + // Ok(()) + // }), + // )?; + + // let instance = module.instantiate(&mut store, Some(imports))?; + // let add_and_print = instance.typed_func::<(i32, i32), ()>(&mut store, "add_and_print")?; + // add_and_print.call(&mut store, (1, 2))?; + + Ok(()) +} |
