native <-> java question

guys is the technique that game engines use to talk with c# similar to JNI
22 Replies
JavaBot
JavaBot3d ago
This post has been reserved for your question.
Hey @kys! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
dan1st
dan1st2d ago
I am not sure what you mean with what game engines use to talk with C# but if you want to call native code from a Java application, you can use the foreign function and memory API
kys
kysOP2d ago
game engines use c# for scriptting they use mono or smthg idk what is memory api
dan1st
dan1st2d ago
so what do you want to interact with in Java there? The "Foreign Function and Memory API" is part of the standard libraries you can use in Java programs and it allows you to call non-Java code and access program memory that isn't managed by the JVM
kys
kysOP2d ago
im making a game engine but instead of c# for scripting i use java core in cpp btw
dan1st
dan1st2d ago
Then you can use the Foreign function and memory API to call the C++ code from Java
kys
kysOP2d ago
hmm
dan1st
dan1st2d ago
but note that requires JDK 22 or later: https://openjdk.org/jeps/454
kys
kysOP2d ago
what about call java from cpp
dan1st
dan1st2d ago
You can use the foreign function and memory API as well essentially you can create an upcall handle from Java code (which is essentially a reference to a Java method) and give that to C++ code
kys
kysOP2d ago
does it only can call function or it can be variable accessable too
dan1st
dan1st2d ago
that's the memory part of the foreign function and memory API
kys
kysOP2d ago
damn
dan1st
dan1st2d ago
you can use an Arena to allocate foreign memory from Java and then pass that memory to native code essentially
kys
kysOP2d ago
is the 'memory API' thing in java.lang.foreign or smthg else
dan1st
dan1st2d ago
yes, that package is the foreign function and memory API
dan1st
dan1st2d ago
You might also want to read https://dev.java/learn/ffm/
Dev.java: The Destination for Java Developers
The Foreign Function and Memory API - Dev.java
The Foreign Function and Memory (FFM) API facilitates Java programs to interoperate with code and data outside the Java runtime without the brittleness and danger of JNI.
kys
kysOP2d ago
ok thank you
JavaBot
JavaBot2d ago
If you are finished with your post, please close it. If you are not, please ignore this message. Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
dan1st
dan1st2d ago
Invoke a C Library Function
that should also work with your C++ code
kys
kysOP2d ago
i though that i have to use getter and setter with JNI for my game engines
JavaBot
JavaBot2d ago
Post Closed
This post has been closed by <@1352291760360914964>.

Did you find this page helpful?