Skip to content

Instantly share code, notes, and snippets.

@buzztaiki
Created May 9, 2013 13:28
Show Gist options
  • Select an option

  • Save buzztaiki/5547436 to your computer and use it in GitHub Desktop.

Select an option

Save buzztaiki/5547436 to your computer and use it in GitHub Desktop.
import java.util.concurrent.Callable;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;
public class RunScript {
public static void main(String args[]) throws Exception {
System.out.println(callable().call());
}
static Callable callable() {
Context cx = Context.enter();
try {
Scriptable scope = cx.initStandardObjects();
String s = "new java.util.concurrent.Callable({call: function(){return [1,2,3].join(',');}})";
Object x = cx.evaluateString(scope, s, "<cmd>", 1, null);
return (Callable)(Context.jsToJava(x, Callable.class));
} finally {
Context.exit();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment