Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@chrisseaton
Created April 25, 2018 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisseaton/0b6037280a7ef8c92f76371ef3a6007d to your computer and use it in GitHub Desktop.
Save chrisseaton/0b6037280a7ef8c92f76371ef3a6007d to your computer and use it in GitHub Desktop.
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Value;
public class ExtendJava {
public static void main(String[] args) {
String language = "js";
try (Context context = Context.newBuilder().allowNativeAccess(true).build()) {
for (String arg : args) {
if (arg.startsWith("-")) {
language = arg.substring(1);
} else {
Value v = context.eval(language, arg);
System.out.println(v);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment