Created
October 24, 2019 02:27
-
-
Save frsyuki/197b16d429545399dc1b9a5713b32ade to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File; | |
import java.io.IOException; | |
import org.graalvm.polyglot.Context; | |
import org.graalvm.polyglot.Source; | |
import org.graalvm.polyglot.Value; | |
public class GraalPolyglot { | |
public static void main(String[] args) throws IOException { | |
Source source = Source.newBuilder("ruby", new File(args[0])).build(); | |
try (Context context = Context.newBuilder().allowAllAccess(true).build()) { | |
context.eval(source); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ java GraalPolyglot test.rb | |
1 | |
$ java -version | |
openjdk version "1.8.0_232" | |
OpenJDK Runtime Environment (build 1.8.0_232-20191009173705.graal.jdk8u-src-tar-gz-b07) | |
OpenJDK 64-Bit GraalVM CE 19.2.1 (build 25.232-b07-jvmci-19.2-b03, mixed mode) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Java.import 'javax.script.ScriptEngineManager' | |
mgr = ScriptEngineManager.new | |
js = mgr.getEngineByExtension("js") | |
js.eval("print(1)") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment