Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use anyhow::Result;
- use wasmtime::*;
- use wasmtime_wasi::{Wasi, WasiCtx};
- fn main() -> Result<()> {
- println!("Initializing...");
- let store = Store::default();
- let wasi = Wasi::new(&store, WasiCtx::new(std::env::args())?);
- println!("Compiling module...");
- let module = Module::from_file(&store, "/home/yolo/hello/target/wasm32-wasi/debug/hello.wasm")?;
- let module2 = Module::from_file(&store, "/home/yolo/hello2/target/wasm32-wasi/debug/hello.wasm")?;
- println!("Instantiating module...");
- let ty = MemoryType::new(Limits::new(322, None));
- let mem = Memory::new(&store, ty);
- let imports = [Extern::from(mem), Extern::from(wasi.get_export("fd_write").unwrap().clone())];
- let instance = Instance::new(&module, &imports)?;
- let instance2 = Instance::new(&module2, &imports)?;
- println!("Extracting export...");
- let run = instance
- .get_func("kek")
- .ok_or(anyhow::format_err!("failed to find `run` function export"))?
- .get0::<i32>()?;
- let run2 = instance2
- .get_func("top")
- .ok_or(anyhow::format_err!("failed to find `run` function export"))?
- .get1::<i32, i32>()?;
- // And last but not least we can call it!
- println!("Calling export...");
- let kek_ptr = run()?;
- //let kek2 = run2(kek_ptr)?;
- //println!("lmao. {:?}", kek2);
- Ok(())
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement