dyon
dyon copied to clipboard
Calling a rust move closure from dyon script
Hey :)
I'm trying to call a move ||
closure from dyon, but that doesn't work. Also I wasn't able to figure out how to do something similar with the current library. Maybe someone has an idea?
pub fn execute<'b>(&mut self, send_dsp_parameter: &dyn FnMut(String, f32) -> ()) {
let mut module = Module::new();
module.add_str(
"set_dsp_parameter",
move |rt: &mut dyon::Runtime| -> Result<(), String> {
let value: f64 = rt.pop()?;
let key: String = rt.pop()?;
println!("{key} {value}");
set_dsp_parameter(key, value);
Ok(())
},
Dfn::nl(vec![Type::Str, Type::F64], Type::Void),
);
self.runtime
.run(&mut Arc::new(module))
.expect("Failed running");
}