From 7c3b9b4f4f2f4ec8fdeb0e77bb853fd22ffaa476 Mon Sep 17 00:00:00 2001 From: Andy Finch Date: Thu, 5 Dec 2019 15:30:20 -0500 Subject: feat: first pass at native plugins (#3372) --- core/lib.rs | 2 ++ core/ops.rs | 2 +- core/plugins.rs | 22 ++++++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 core/plugins.rs (limited to 'core') diff --git a/core/lib.rs b/core/lib.rs index 31f717769..f1becb5d7 100644 --- a/core/lib.rs +++ b/core/lib.rs @@ -14,6 +14,7 @@ mod libdeno; mod module_specifier; mod modules; mod ops; +mod plugins; mod resources; mod shared_queue; @@ -27,6 +28,7 @@ pub use crate::libdeno::PinnedBuf; pub use crate::module_specifier::*; pub use crate::modules::*; pub use crate::ops::*; +pub use crate::plugins::*; pub use crate::resources::*; pub fn v8_version() -> &'static str { diff --git a/core/ops.rs b/core/ops.rs index 6dc0a7323..c840ed979 100644 --- a/core/ops.rs +++ b/core/ops.rs @@ -27,7 +27,7 @@ pub type CoreError = (); pub type CoreOp = Op; /// Main type describing op -type OpDispatcher = +pub type OpDispatcher = dyn Fn(&[u8], Option) -> CoreOp + Send + Sync + 'static; #[derive(Default)] diff --git a/core/plugins.rs b/core/plugins.rs new file mode 100644 index 000000000..50271d53a --- /dev/null +++ b/core/plugins.rs @@ -0,0 +1,22 @@ +use crate::libdeno::PinnedBuf; +use crate::ops::CoreOp; + +pub type PluginInitFn = fn(context: &mut dyn PluginInitContext); + +pub trait PluginInitContext { + fn register_op( + &mut self, + name: &str, + op: Box) -> CoreOp + Send + Sync + 'static>, + ); +} + +#[macro_export] +macro_rules! init_fn { + ($fn:path) => { + #[no_mangle] + pub fn deno_plugin_init(context: &mut dyn PluginInitContext) { + $fn(context) + } + }; +} -- cgit v1.2.3