2017-05-10 00:13:54 +02:00
|
|
|
#[macro_export]
|
|
|
|
|
macro_rules! impl_plugin {
|
2017-05-27 16:56:44 +02:00
|
|
|
($plugin:ty, $proxy:ident, [$(($evt:ty, $pri:expr) => $func:ident),*]) => {
|
2017-05-10 00:13:54 +02:00
|
|
|
impl $crate::plugin::Plugin for $plugin {
|
|
|
|
|
fn get_proxy(&mut self) -> &mut $crate::plugin::PluginProxy {
|
|
|
|
|
&mut self.$proxy
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[allow(unused_variables)]
|
|
|
|
|
impl $crate::plugin::PluginInit for $plugin {
|
|
|
|
|
fn init( dispatcher: &mut $crate::event::Dispatcher
|
|
|
|
|
, me: ::std::sync::Arc<Box<$crate::plugin::Plugin>>) {
|
|
|
|
|
$(
|
2017-05-27 16:56:44 +02:00
|
|
|
let new_arc = me.clone();
|
|
|
|
|
dispatcher.register($pri, move |e: &$evt| {
|
|
|
|
|
let p = new_arc.as_any().downcast_ref::<$plugin>().unwrap();
|
|
|
|
|
p . $func(e)
|
2017-05-10 00:13:54 +02:00
|
|
|
});
|
|
|
|
|
)*
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2017-05-27 16:56:44 +02:00
|
|
|
($plugin:ty, $proxy:ident, [$(($evt:ty, $pri:expr) => $func:ident),*,]) => {
|
|
|
|
|
impl_plugin!($plugin, $proxy, [$(($evt, $pri) => $func),*]);
|
2017-05-10 00:13:54 +02:00
|
|
|
};
|
|
|
|
|
}
|