CertainLach / jrsonnet

Rust implementation of Jsonnet language
MIT License
304 stars 33 forks source link

use callback from wasm-bindgen in jrsonnet #149

Closed rahul007-bit closed 3 months ago

rahul007-bit commented 7 months ago

I am working to create javascript bindings with jrsonnet using wasm-bindgen. I am stuck at native callback since I can't use wasm-bindgen's js_sys::Function in add_native is there any way, I can use the callback received from wasm-bindgen in jrsonnet?

CertainLach commented 6 months ago

You can wrap js_sys::Function in newtype wrapper and implement NativeCallbackHandler for it.

struct JsCallback(js_sys::Function);
impl NativeCallbackHandler for JsCallback {
   ...
}
std_opts.add_native(NativeCallback::new(
   vec!["param1".to_owned(), "param2".to_owned()],
   JsCallback(js_function)
))