fix up the event system, no more unsafe!
This commit is contained in:
parent
cdf665454f
commit
c326d5b07e
8 changed files with 110 additions and 150 deletions
|
|
@ -1,6 +1,6 @@
|
|||
#[macro_export]
|
||||
macro_rules! impl_plugin {
|
||||
($plugin:ty, $proxy:ident, [$($evt:ty => $pri:expr),*]) => {
|
||||
($plugin:ty, $proxy:ident, [$(($evt:ty, $pri:expr) => $func:ident),*]) => {
|
||||
impl $crate::plugin::Plugin for $plugin {
|
||||
fn get_proxy(&mut self) -> &mut $crate::plugin::PluginProxy {
|
||||
&mut self.$proxy
|
||||
|
|
@ -12,15 +12,17 @@ macro_rules! impl_plugin {
|
|||
fn init( dispatcher: &mut $crate::event::Dispatcher
|
||||
, me: ::std::sync::Arc<Box<$crate::plugin::Plugin>>) {
|
||||
$(
|
||||
dispatcher.register($pri, unsafe {
|
||||
$crate::event::EventProxy::new::<$plugin>(me.clone())
|
||||
let new_arc = me.clone();
|
||||
dispatcher.register($pri, move |e: &$evt| {
|
||||
let p = new_arc.as_any().downcast_ref::<$plugin>().unwrap();
|
||||
p . $func(e)
|
||||
});
|
||||
)*
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
($plugin:ty, $proxy:ident, [$($evt:ty => $pri:expr),*,]) => {
|
||||
impl_plugin!($plugin, $proxy, [$($evt => $pri),*]);
|
||||
($plugin:ty, $proxy:ident, [$(($evt:ty, $pri:expr) => $func:ident),*,]) => {
|
||||
impl_plugin!($plugin, $proxy, [$(($evt, $pri) => $func),*]);
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue