Fork me on GitHub
#graalvm
<
2023-03-22
>
DrTalos17:03:06

Just wondering if anyone can point me at some example code that accepts and calls a c callback in a shared library compiled with Graal. I imagine I can work it out from the docs, but I'm fairly new to Graal, and the docs are a bit on the sparse side, so an example would be very useful. I haven't been able to turn one up, even just looking for one in Java.

phronmophobic18:03:32

I remember looking into this previously, but I don't think I ever found a direct method. However, graalvm now supports JNA, which does let you call function pointers, https://javadoc.io/static/net.java.dev.jna/jna/5.13.0/com/sun/jna/Function.html. I like using JNA since it's pretty straightforward and works under the jvm and graalvm.

DrTalos19:03:05

OK, thank you very much! This looks really helpful. Doing things like this, that not many people have had to do yet, reminds me of my early days programming, before widely available internet. It's easy to forget how essential things like StackOverflow, etc. are for getting nuts and bolts stuff done.

👍 2
phronmophobic19:03:18

http://grep.app is really a great resource for more obscure stuff like this.

DrTalos19:03:15

Thanks very much for pointing it out to me- I hadn;t seen it before.

phronmophobic19:03:55

Pretty sure I first learned about it from this slack. It's really too bad that github search isn't very useful.

DrTalos19:03:36

I did try Chatgpt, as a lark. It kept getting this problem confused with calling a normal Java callback though, I assume because there is so little available online about it- it did make me think that the demise of actual programmers has been oversold.