p and l are the message pointer and length in wasm memory.
(mut ctx: FunctionEnvMut<Ctx>, p: i32, l: i32)
| 73 | |
| 74 | // p and l are the message pointer and length in wasm memory. |
| 75 | fn print(mut ctx: FunctionEnvMut<Ctx>, p: i32, l: i32) -> i32 { |
| 76 | let (c, s) = ctx.data_and_store_mut(); |
| 77 | let mut msg = vec![0u8; l as usize]; |
| 78 | let m = c.mem.as_ref().unwrap().view(&s); |
| 79 | if m.read(p as u64, &mut msg).is_err() { |
| 80 | return -1; |
| 81 | } |
| 82 | let s = std::str::from_utf8(&msg).expect("print got non-utf8 str"); |
| 83 | println!("{s}"); |
| 84 | 0 |
| 85 | } |
| 86 | |
| 87 | fn main() { |
| 88 | let mut store = Store::default(); |