diff --git a/src/wrapper/clap.rs b/src/wrapper/clap.rs index 4837165e..c81fdf56 100644 --- a/src/wrapper/clap.rs +++ b/src/wrapper/clap.rs @@ -44,7 +44,7 @@ macro_rules! nih_export_clap { ::nih_plug::wrapper::clap::CLAP_PLUGIN_FACTORY_ID, ) } { - &(*factory).clap_plugin_factory() as *const _ as *const ::std::ffi::c_void + &(*factory).clap_plugin_factory as *const _ as *const ::std::ffi::c_void } else { std::ptr::null() } diff --git a/src/wrapper/clap/factory.rs b/src/wrapper/clap/factory.rs index be9e75f2..43227335 100644 --- a/src/wrapper/clap/factory.rs +++ b/src/wrapper/clap/factory.rs @@ -1,13 +1,16 @@ use clap_sys::plugin_factory::clap_plugin_factory; use std::marker::PhantomData; -use std::mem; use crate::ClapPlugin; /// The plugin's factory. Initialized using a lazy_static from the entry poiunt's `get_factory()` /// function. From this point onwards we don't need to generate code with macros anymore. #[doc(hidden)] +#[repr(C)] pub struct Factory { + // Keep the vtable as the first field so we can do a simple pointer cast + pub clap_plugin_factory: clap_plugin_factory, + /// The type will be used for constructing plugin instances later. _phantom: PhantomData

, } @@ -15,17 +18,18 @@ pub struct Factory { impl Default for Factory

{ fn default() -> Self { Self { + clap_plugin_factory: clap_plugin_factory { + get_plugin_count: Self::get_plugin_count, + get_plugin_descriptor: todo!(), + create_plugin: todo!(), + }, _phantom: PhantomData, } } } impl Factory

{ - pub fn clap_plugin_factory(&self) -> clap_plugin_factory { - clap_plugin_factory { - get_plugin_count: todo!(), - get_plugin_descriptor: todo!(), - create_plugin: todo!(), - } + unsafe extern "C" fn get_plugin_count(_factory: *const clap_plugin_factory) -> u32 { + 1 } }