4 ms·
Calling C is easy. But how do you call C++? Shiboken has a language that let's you express ownership properties on C++ data structures/methods/functions. It's t
by iso8859-1 2y ago
Calling C is easy. But how do you call C++? Shiboken has a language that let's you express ownership properties on C++ data structures/methods/functions. It's tailored to generating Python FFI bindings though. It would be so nice if there were a cross-platform language to do this.
- secondcoming 2y agoYou put your C++ behind a C API.
- p0w3n3d 2y agoThis is something new. Before it you had to create a native-compatible shared library that returns jString/jObject instead or use a proxy which did this for you (JNA). Let's see what happens next, maybe even shiboken
- qweqwe14 2y agoThe answer is basically you don't. It's impossible to make a sane, stable FFI for a language unless you put it behind a C ABI, which is relatively basic, but this is exactly why it's most suitable for FFI: implementing support for calling C functions is way more trivial than figuring out how to call the latest C++/Rust/etc monstrosity.
- zozbot234 2y ago> The answer is basically you don't. It's impossible to make a sane, stable FFI for a language unless you put it behind a C ABI The Swift folks have put a lot of effort into attaining a stable ABI that's native to their language. They can achieve that because Swift is the officially endorsed language for development on Mac OS and iOS, so it (together with the platform itself) can set a standard that other languages will have to live with. In a way, software VM's like the JVM and CLR can also be said to define 'ABIs' of sorts within their runtime, that every language implementation on these runtimes will have to deal with.
- Dwedit 2y agoThere do exist ABIs that aren't the C ABI. But saying "use the C ABI" is far more portable than anything else. I can also point to the GCC Inline Assembler as an excellent way to call arbitrary functions whether they implement the standard C procedure call standard or not. By providing the list of arguments and what register they correspond to, along with the clobber list, you know everything you need to know to call the function. So it's more suitable for "fastcall" type functions where you need the arguments to correspond to particular registers. But of course, ASM isn't portable.
- neonsunset 2y agoSwift ABI proves this to be wrong, but also showcases the complexity that goes with ABI of such kind.
- mike_hearn 2y agoThere's javacpp which can do that.
- imtringued 2y agoI don't know why people don't know this, but you can just use GObject.