1use mlua::Lua;
2
3use plugin_runtime::*;
4
5pub fn main() -> anyhow::Result<()> {
6 let plugin = WasmPlugin {
7 source_bytes: include_bytes!(
8 "../plugin/target/wasm32-unknown-unknown/release/cargo_test.wasm"
9 )
10 .to_vec(),
11 store_data: (),
12 };
13
14 let mut sum = Wasm::init(plugin)?;
15 let strings = "I hope you have a nice day"
16 .split(" ")
17 .map(|x| x.to_string())
18 .collect();
19 let result = sum.sum_lengths(strings);
20
21 dbg!(result);
22
23 Ok(())
24}
25
26// struct SumLengths {
27// sum_lengths: Handle,
28// }
29
30// impl Interface for SumLengths {
31// fn from_runtime<T: Runtime>(runtime: &mut T) -> Option<Self> {
32// Some(SumLengths {
33// sum_lengths: runtime.handle_for("sum_lengths")?,
34// })
35// }
36// }
37
38// impl SumLengths {
39// fn sum_lengths<T: Runtime>(&self, runtime: &mut T, strings: Vec<String>) -> Option<usize> {
40// runtime.call(&self.sum_lengths, strings).ok()
41// }
42// }
43
44// #[plugin::interface]
45trait SumLengths {
46 fn sum_lengths(&mut self, strings: Vec<String>) -> usize;
47}
48
49impl<T: Runtime> SumLengths for T {
50 fn sum_lengths(&mut self, strings: Vec<String>) -> usize {
51 let result = self.call("sum_lengths", strings).ok().unwrap();
52 return result;
53 }
54}