summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/lib.rs2
-rw-r--r--core/ops.rs2
-rw-r--r--core/plugins.rs22
3 files changed, 25 insertions, 1 deletions
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<CoreError>;
/// Main type describing op
-type OpDispatcher =
+pub type OpDispatcher =
dyn Fn(&[u8], Option<PinnedBuf>) -> 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<dyn Fn(&[u8], Option<PinnedBuf>) -> 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)
+ }
+ };
+}