[graalvm-users] pass java object to llvm function

Lukas Stadler lukas.stadler at oracle.com
Thu Jan 21 06:11:25 PST 2021

Yes, passing Java classes to the LLVM printPoint function works.
Using the “cpart.so” file from the JavaScript example, it could look like this:

import java.io.*;
import org.graalvm.polyglot.*;

class Polyglot {
    public static class Point {
        public int x;
        public int y;
    public static void main(String[] args) throws IOException {
        Context polyglot = Context.newBuilder().allowAllAccess(true).build();
        File file = new File("cpart.so");
        Source source = Source.newBuilder("llvm", file).build();
        Value cpart = polyglot.eval(source);
        Value printPoint = cpart.getMember("printPoint");
        printPoint.execute(new Point());

$ bin/javac Polyglot.java
$ bin/java Polyglot


> On 21.01.2021, at 04:40, Darrell Schiebel <darrell at schiebel.us> wrote:
> I am trying to reproduce the JavaScript example at:
> https://www.graalvm.org/reference-manual/llvm/Interoperability/ <https://www.graalvm.org/reference-manual/llvm/Interoperability/>
> using Java instead of JavaScript. In general it is straightforward, but I'm having trouble passing a Java object to a C++ function to implement the equivalent of:
> // Additionally, pass a JS object to a native function
> cpart.printPoint({x: 17, y: 42});
> Is it possible to pass a Point object declared and instantiated in Java to the LLVM printPoint function?
> thanks,
> Darrell
> _______________________________________________
> GraalVM-Users mailing list
> GraalVM-Users at oss.oracle.com
> https://oss.oracle.com/mailman/listinfo/graalvm-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://oss.oracle.com/pipermail/graalvm-users/attachments/20210121/6f77e0cb/attachment.html 

More information about the GraalVM-Users mailing list