Skip to content

Commit

Permalink
feat: support wrapped plugin ops
Browse files Browse the repository at this point in the history
  • Loading branch information
afinch7 committed Jun 2, 2020
1 parent 9c59a4b commit 8315f2b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cli/ops/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl<'a> plugin_api::Interface for PluginInterface<'a> {
fn register_op(
&mut self,
name: &str,
dispatch_op_fn: plugin_api::DispatchOpFn,
dispatch_op_fn: Box<plugin_api::DispatchOpFn>,
) -> OpId {
let plugin_lib = self.plugin_lib.clone();
self.isolate_state.op_registry.register(
Expand Down
5 changes: 3 additions & 2 deletions core/plugin_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ pub use crate::ZeroCopyBuf;

pub type InitFn = fn(&mut dyn Interface);

pub type DispatchOpFn = fn(&mut dyn Interface, &[u8], &mut [ZeroCopyBuf]) -> Op;
pub type DispatchOpFn =
dyn Fn(&mut dyn Interface, &[u8], &mut [ZeroCopyBuf]) -> Op;

pub trait Interface {
fn register_op(&mut self, name: &str, dispatcher: DispatchOpFn) -> OpId;
fn register_op(&mut self, name: &str, dispatcher: Box<DispatchOpFn>) -> OpId;
}
4 changes: 2 additions & 2 deletions test_plugin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use futures::future::FutureExt;

#[no_mangle]
pub fn deno_plugin_init(interface: &mut dyn Interface) {
interface.register_op("testSync", op_test_sync);
interface.register_op("testAsync", op_test_async);
interface.register_op("testSync", Box::new(op_test_sync));
interface.register_op("testAsync", Box::new(op_test_async));
}

fn op_test_sync(
Expand Down

0 comments on commit 8315f2b

Please sign in to comment.