How to call a Rust function from JanetClient? #13
Replies: 1 comment
-
Nevermind I figured it out – turns out you don't need to use use janetrs::{client::JanetClient, env::CFunOptions, janet_fn, Janet};
#[janet_fn(arity(fix(0)))]
fn rust_hello(args: &mut [Janet]) -> Janet {
println!("Hello world!");
Janet::nil()
}
fn main() {
let mut janet = JanetClient::init_with_default_env().unwrap();
janet.add_c_fn(CFunOptions::new(c"rust/hello", rust_hello));
let result = janet.run("(rust/hello)");
println!("{:?}", result);
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
My goal is to embed Janet into a Rust program as a sort of plugin language, so I need a way to both interpret Janet scripts from Rust and to call Rust functions from those Janet scripts.
I'm following the example of declaring a Janet module, but I can't figure out how to call Rust functions from JanetClient. Here's what I have so far:
This just gets me a CompileError (I think the declared "rust" module is not available to the JanetClient, but I don't know how to fix it)
Beta Was this translation helpful? Give feedback.
All reactions