-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
module init macro #68
Comments
Not quite sure I follow. You would like to write Rust code that can be easily compiled to qjs CLI compatible native modules? |
Yes, which requires an entrypoint function with that signature. It'd be nice to have a macro that lets you write a function with the rust-wrapped types and the macro will wrap it appropriately to expose the C types. So basically you'd build with |
That would indeed be convenient. I guess the interesting questions are around how to provide variables, functions, ... from Rust in a ergonomic way. I'll probably work on a Webassembly runtime and some other features like async integration first, but contributions are definitely welcome. It would definitely help if you could sketch out how you would expect code to look like. |
I might get around to contributing it myself, if I can find the time at some point and no one else gets to it first. My thinking is something like: use quick_js::{Context,Module};
#[quickjs_init_module(my_module)]
fn init_module(context: Context, name: String) -> Module {
context.new_module(name, |module| {
module.add_callback("add", |a: i32, b: i32| a + b).unwrap();
})
} For reference, here's what it looks like in C: https://github.com/Qard/quickjs-glfw/blob/master/glfw.c#L178-L188 |
It'd be cool to have a fancy macro to build the extern function required to create a native module that can be imported by the
qjs
CLI. Withqjs
you can build and import native modules from*.so
files by simply having a function something like:Then in JS you just do:
The text was updated successfully, but these errors were encountered: