use mlua::Lua; use plugin_runtime::*; pub fn main() -> anyhow::Result<()> { let plugin = WasmPlugin { source_bytes: include_bytes!( "../plugin/target/wasm32-unknown-unknown/release/cargo_test.wasm" ) .to_vec(), store_data: (), }; let mut sum = Wasm::init(plugin)?; let strings = "I hope you have a nice day" .split(" ") .map(|x| x.to_string()) .collect(); let result = sum.sum_lengths(strings); dbg!(result); Ok(()) } // struct SumLengths { // sum_lengths: Handle, // } // impl Interface for SumLengths { // fn from_runtime(runtime: &mut T) -> Option { // Some(SumLengths { // sum_lengths: runtime.handle_for("sum_lengths")?, // }) // } // } // impl SumLengths { // fn sum_lengths(&self, runtime: &mut T, strings: Vec) -> Option { // runtime.call(&self.sum_lengths, strings).ok() // } // } // #[plugin::interface] trait SumLengths { fn sum_lengths(&mut self, strings: Vec) -> usize; } impl SumLengths for T { fn sum_lengths(&mut self, strings: Vec) -> usize { let result = self.call("sum_lengths", strings).ok().unwrap(); return result; } }