-
-
Save lucaswerkmeister/391b59e415d17cd2d8282170338a23cf to your computer and use it in GitHub Desktop.
A brief look at Graal
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
public class Hello { | |
public static void main(String[] args) { | |
String name = args.length > 0 ? args[0] : "World"; | |
System.out.println("Hello, " + name + "!"); | |
} | |
} |
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 org.graalvm.polyglot.*; | |
public class HelloPolyglot { | |
public static void main(String[] args) { | |
String name = args.length > 0 ? args[0] : "World"; | |
System.out.println("Hello, " + name + ", from Java!"); | |
Context context = Context.create(); | |
context.getPolyglotBindings().putMember("name", name); | |
context.eval("js", | |
"const name = Interop.import('name');\n" + | |
"print('Hello, ' + name + ', from JavaScript!');"); | |
} | |
} |
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
jsPlus = eval.polyglot('js', 'function(s1, s2) { return s1 + s2; }') | |
rubyOne = eval.polyglot('ruby', '1') | |
pythonOne = eval.polyglot('python', '1') | |
print(jsPlus(rubyOne, pythonOne)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The Java examples can be compiled with
javac
(assuming Graal’sbin
is in thePATH
) and run withjava
; instead of running them, you can also create native images withnative-image
(add--language:js
forHelloPolyglot
).