[−]Macro dart::export_dart_functions
Creates a Registerer
which exports Dart native extension functions.
Usage
- Create your functions.
use dart::prelude::*; use std::ffi::CString; fn my_function(args: NativeArguments) { args.set_return(DString::new("Hello, World").safe_handle()); } fn my_async_function(message: CObject, _from_port: Port) { if let CObject::SendPort(port) = message { let port = unsafe { Port::from_port(port.0.id) }.unwrap(); port.post_cobject(CObject::String(CString::new("Hello, Async World").unwrap())); } else { panic!("Didn't get a port to reply!"); } }
- Export your functions using the syntax
// Creates a set of exports called `my_exports`. dart::export_dart_functions!(my_exports: ["function1" -> my_function], ["function2service_port" -> my_async_function as async] );