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
Call Java functions from duktape #29
Comments
I was messing with this a while ago. I wrote an API but not an implementation 😀 interface Math {
int add(int one, int two);
}
// Bind a JS object to Java API.
Math math = duktape.proxy("math", Math.class); class Listener {
void onSomething(String result) {
System.out.println(result);
}
}
// Bind a Java instance to a JS object.
duktape.bind("listener", new Listener()); |
This looks quite fun. |
That looks awesome! And much simpler than the API of Rhino. |
Any news on this? |
I'm hoping to get to this soon, likely in the next week or two. |
That's good news, thanks for the update! |
This has been implemented! |
Ah, that's cool! Thanks. Going to give it a try soon. I found some example usages in the unit tests, looks easy to use. A bit of docs/examples would be welcome though. |
Absolutely, I'm updating the README next.. |
I just fiddled around with this new feature, it works great, also gives back useful error stack traces. I really love the minimalist interface. Thanks! Just as a side note: I worked a lot with rhino, which supports not only primitives but also passing Java classes as arguments and return types. In practice this works really painful though, and we ended up passing objects as stringified JSON. So... please just stick to support for primitives :). One question: what is the reason that you only support a class interface? It would be convenient if you can also just pass a class I think. |
We use an interface to discourage users from passing arbitrary types like |
That makes sense, thanks for the explanation. |
It would be useful to be able to call native Java/Android functions from within JavaScript, similar to how Rhino allows importing native functions.
For my specific case there is no need to implement full support for conversion between Java and JS objects, it would be enough to just be able to call a function with primitive arguments like double, String, int.
The text was updated successfully, but these errors were encountered: