-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
628 additions
and
551 deletions.
There are no files selected for viewing
File renamed without changes.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
[workspace] | ||
resolver = "2" | ||
members = [ | ||
"components/macros", | ||
"components/injector", | ||
"components/llrt", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use super::engine::{Invocation, JsEngine, JsObject, JsResult, JsValue}; | ||
|
||
/// A JsCallable is the data structure used to represent a function in LLRT | ||
/// that is callable from JavaScript. It contains the Rust function pointer, | ||
/// and the function's name. Note that privileges are handled by the HLRT. | ||
pub struct JsCallable { | ||
/// The name of the function, as it will appear in JavaScript. | ||
pub name: &'static str, | ||
|
||
/// The function pointer. | ||
pub func: fn(Invocation) -> JsResult<JsValue>, | ||
} | ||
|
||
impl JsCallable { | ||
pub const fn new(name: &'static str, func: fn(Invocation) -> JsResult<JsValue>) -> Self { | ||
Self { name, func } | ||
} | ||
} | ||
|
||
pub fn register_all(engine: &JsEngine, dest: &JsObject) -> JsResult<()> { | ||
for callable in inventory::iter::<JsCallable> { | ||
dest.set(callable.name, engine.create_function(callable.func))?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
inventory::collect!(JsCallable); | ||
|
||
#[macro_export] | ||
macro_rules! register_js_callable { | ||
($name:expr, $func:ident) => { | ||
inventory::submit! { | ||
crate::runtime::callable::JsCallable::new( | ||
$name, | ||
$func | ||
) | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.