use sm_ext::{native, register_natives, IExtension, IExtensionInterface, IPluginContext, IShareSys, SMExtension};
use std::ffi::CStr;
#[native]
fn test_native_add(_ctx: &IPluginContext, a: i32, b: i32) -> i32 {
a + b
}
#[native]
fn test_native_void(_ctx: &IPluginContext) {}
#[native]
fn test_native_error(_ctx: &IPluginContext) -> Result<(), &'static str> {
Err("This is an error...")
}
#[native]
#[allow(clippy::too_many_arguments, clippy::many_single_char_names)]
fn test_native(ctx: &IPluginContext, a: i32, b: f32, c: &CStr, d: &mut i32, e: &mut f32, f: Option<i32>, g: Option<f32>, h: Option<&str>) -> f32 {
println!(">>> {:?} {:?} {:?} {:?} {:?} {:?} {:?} {:?} {:?}", ctx, a, b, c, d, e, f, g, h);
*d = 47;
*e = 1.5;
5.0
}
#[derive(Default, SMExtension)]
#[extension(name = "Rusty", description = "Sample extension written in Rust")]
pub struct MyExtension;
impl IExtensionInterface for MyExtension {
fn on_extension_load(&mut self, myself: IExtension, sys: IShareSys, late: bool) -> Result<(), Box<dyn std::error::Error>> {
println!(">>> Rusty extension loaded! me = {:?}, sys = {:?}, late = {:?}", myself, sys, late);
register_natives!(
&sys,
&myself,
[
("Rust_Add", test_native_add), ("Rust_Void", test_native_void), ("Rust_Error", test_native_error), ("Rust_Test", test_native), ]
);
Ok(())
}
}