Hi Dan.

On 16/05/2010 9:36 AM, Dan Howard wrote:
Basically I'm trying to pass a javaScript function to a Java method to
act as a callback to the script.
...
public void callFromRhino(Object callback) {

Don't make this take an Object. Instead, have it take an interface with a single method on it whose signature matches the desired JS function. For example:

  interface EventCallback {
    void eventOccurred(int eventType);
  }

  public void callFromRhino(EventCallback callback) {
    // some time later you might call callback.eventOccurred(123)
  }

and then in JS you can do:

  function junk(eventType) { ... }

  test.callFromRhino(junk);

In your example it looks like you don't have any parameters in your callback function, so you could just use a Runnable:

  public void callFromRhino(Runnable callback) {
    // some time later you might call callback.run()
  }

_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to