3 ms·
I'm not sure scripting-language interop is holding back Swift, but ... > call a swift compiled extension from Python/JS/Ruby/PHP The story there is excellent.
by w10-1 2y ago
I'm not sure scripting-language interop is holding back Swift, but ...
> call a swift compiled extension from Python/JS/Ruby/PHP
The story there is excellent.
Here's a Swift function callable from C
@cdecl("myfunc")
public static func f(){...}
C/C++ types are mostly handled automatically (including sharing memory management), but it can be tricky.
To build a library to load and call from any language:
swiftc mine.swift -emit-library -o libmine.dylib
E.g., calling from java 22 FFI:
https://foojay.io/today/java-panama-polyglot-swift-part-2/ https://foojay.io/today/java-panama-polyglot-swift-part-2/
But most people instead use a slower json server network interface because (sadly) json is the lingua franca for scripting and Swift Codable makes it trivial to map the json to a swift type.