native <-> java question

guys is the technique that game engines use to talk with c# similar to JNI
22 Replies
JavaBot
JavaBot4mo 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
dan1st4mo 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
coolsigma103
coolsigma103OP4mo ago
game engines use c# for scriptting they use mono or smthg idk what is memory api
dan1st
dan1st4mo 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
coolsigma103
coolsigma103OP4mo ago
im making a game engine but instead of c# for scripting i use java core in cpp btw
dan1st
dan1st4mo ago
Then you can use the Foreign function and memory API to call the C++ code from Java
coolsigma103
coolsigma103OP4mo ago
hmm
dan1st
dan1st4mo ago
but note that requires JDK 22 or later: https://openjdk.org/jeps/454
coolsigma103
coolsigma103OP4mo ago
what about call java from cpp
dan1st
dan1st4mo 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
coolsigma103
coolsigma103OP4mo ago
does it only can call function or it can be variable accessable too
dan1st
dan1st4mo ago
that's the memory part of the foreign function and memory API
coolsigma103
coolsigma103OP4mo ago
damn
dan1st
dan1st4mo ago
you can use an Arena to allocate foreign memory from Java and then pass that memory to native code essentially
coolsigma103
coolsigma103OP4mo ago
is the 'memory API' thing in java.lang.foreign or smthg else
dan1st
dan1st4mo ago
yes, that package is the foreign function and memory API
dan1st
dan1st4mo 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.
coolsigma103
coolsigma103OP4mo ago
ok thank you
JavaBot
JavaBot4mo 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
dan1st4mo ago
Invoke a C Library Function
that should also work with your C++ code
coolsigma103
coolsigma103OP4mo ago
i though that i have to use getter and setter with JNI for my game engines
JavaBot
JavaBot4mo ago
Post Closed
This post has been closed by <@1352291760360914964>.

Did you find this page helpful?