Is it possible? I know about JNA and had the example code from tutorial site worked with Java before but no success with Fan so far. Very few results from this forum contains the word "JNA" and none helps. For example, I want to call function sayHi() which print "Hi" from libTest.dll from Fan. Please give me a working code. Thanks :)
SlimerDudeTue 12 Feb 2019
Fantom can call native Java, as outlined in Java FFI, so if you can create a .dll that you can call from Java then you can call it from Fantom.
I've not written any native C code that gets called from Java or Fantom, but Sass4f does use JNA to call libSass. What I found there is that the .dll (or linux .so) files need to be copied to the Fantom bin/ directory to be picked up (and the .jar files in lib/java/ext/) - so I'd try that if you're having problems.
andyTue 12 Feb 2019
There is no direct support for this in Fantom proper.
Assuming you intend the code to run on the JVM, you can use JNI. If you are looking for a simple example you can poke around here:
This is pretty specific to JNI, not much Fantom outside the peer method. So googling around for JNI is probably your best bet aside from the above code samples.
Ilove:=Tue 12 Feb 2019
@andy: I want to go with JNA not JNI. I will try testing myself and report if successful.
andyWed 13 Feb 2019
Heh I did not know about JNA -- that's pretty cool.
Ilove:=Thu 14 Feb 2019
It seemed many peoples here just stick with what proved to work but not update to newer things. Steve hear JavaFX the first time from me (strange, it's available since Java 7) and now andy discover JNA also through me. I have to admit, because I am totally amateur and spend most of my time reading about cool stuffs but very little I practice so I know many new things but I completely impossible to build something that works. I got defeated by Fantom domkit recently he he.
Ilove:= Mon 11 Feb 2019
Is it possible? I know about JNA and had the example code from tutorial site worked with Java before but no success with Fan so far. Very few results from this forum contains the word "JNA" and none helps. For example, I want to call function sayHi() which print "Hi" from libTest.dll from Fan. Please give me a working code. Thanks :)
SlimerDude Tue 12 Feb 2019
Fantom can call native Java, as outlined in Java FFI, so if you can create a
.dll
that you can call from Java then you can call it from Fantom.I've not written any native C code that gets called from Java or Fantom, but Sass4f does use JNA to call
libSass
. What I found there is that the.dll
(or linux.so
) files need to be copied to the Fantombin/
directory to be picked up (and the.jar
files inlib/java/ext/
) - so I'd try that if you're having problems.andy Tue 12 Feb 2019
There is no direct support for this in Fantom proper.
Assuming you intend the code to run on the JVM, you can use JNI. If you are looking for a simple example you can poke around here:
This is pretty specific to JNI, not much Fantom outside the peer method. So googling around for JNI is probably your best bet aside from the above code samples.
Ilove:= Tue 12 Feb 2019
@andy: I want to go with JNA not JNI. I will try testing myself and report if successful.
andy Wed 13 Feb 2019
Heh I did not know about JNA -- that's pretty cool.
Ilove:= Thu 14 Feb 2019
It seemed many peoples here just stick with what proved to work but not update to newer things. Steve hear JavaFX the first time from me (strange, it's available since Java 7) and now andy discover JNA also through me. I have to admit, because I am totally amateur and spend most of my time reading about cool stuffs but very little I practice so I know many new things but I completely impossible to build something that works. I got defeated by Fantom domkit recently he he.