Hello all, I’ve been recently experimenting with apple Swift’s FFI and the command line and it is really easy to bind to c libraries on macOS. I’m just wondering how the FFI works with the Elements compiler. I have seen the FFI section in the documentation, but I’m a bit confused by it. Can I call C code using this? Can I create a static library and link my Silver code against it or is it similar to Python’s ctypes library that only allows dynamic loading and calling of foreign functions?
The answer is very dependent on the target you use for Silver. With Silver for Java you can only use JNI (because java can only use jni). With Silver for .NET you can use pinvoke, which lets you call pretty much everything you need but requires writing signatures. With Silver for Island or Toffee (any platform) we support importing C header files:
Essentially you need to tell the compiler what needs to be imported (which C entry points); where it’s defined and what namespace it should end up in.
Awesome! I figured .Net and JVM would use their respective apis, FXGen is definitely what I am looking for.
Thank you Carlo!