On Fri, Dec 16, 2011 at 07:17:11PM -0800, Dan Hitt wrote:
I tried your technique and i can pass at least integers and strings (as const char*) to software written in c. (I have not tried sending across large amounts of data in arrays, or anything like that.)
You don’t have to worry about either the size or the complexity of the arguments you pass to a C function: as far as Vala is concerned, it doesn’t matter, as all Vala code gets compiled to C code eventually. Complex types with unusual memory management requirements might be slightly more difficult to pass around while maintaining correct reference counting semantics, but for the common case bridging C code and Vala code is stupid easy.
Is this written up on http://valadoc.org anywhere?
My first thought was that it had to be mentioned in the Vala Tutorial[1] somewhere, but that doesn’t seem to be the case. There is an example[2] on the wiki on how to provide a C implementation for an interface defined in Vala, but it’s needlessy complex because it mostly deals with GObject machinery. Maybe it would be a good idea to provide a short example on how to call a C function from Vala code, and spend a couple of words about the feature in the Tutorial? It certainly does come in handy to handle some corner cases–eg. having a function that behaves differently on UNIX and on Windows, when using a cross–compiler to build the application. [1] https://live.gnome.org/Vala/Tutorial [2] https://live.gnome.org/Vala/MultiImplementInC -- Andrea Bolognani <eof kiyuko org> Resistance is futile, you will be garbage collected.
Attachment:
signature.asc
Description: Digital signature