Am 24.03.2010 23:59, Jordan Stinson wrote:
> Hi there,
> 
> I'd like to hack on an existing GLib based C project using vala. Basically
> what I'm doing is, at the beginning of my build process, using valac to
> generate .c and .h files from my .vala files and then just compiling the
> generated files the way I would any .c or .h file. This is probably not the
> best way, but seems to be working alright for the most part. My problem is
> that I'm having a hard time accessing my existing C code from my Vala code.
> Is there an easy way to do this? I've tried writing my own .vapi files (I
> didn't have any luck with the tool that came with vala), but I can't find
> any decent documentation on how to write these. Does any exist? Do I need
> one of these files to call existing C code or is there another way?

You can use the 'extern' keyword if you do not want to write a vapi file:

----- source1.c ---------------------------------------------------------
int my_c_function (const char *foo, double bar)
{
        return 42;
}
-------------------------------------------------------------------------

----- source2.vala ------------------------------------------------------
extern int my_c_function (string foo, double bar);

void main () {
        stdout.printf ("%d\n", my_c_function ("hello", 0.75));
}
-------------------------------------------------------------------------

Compile:

$ valac source1.c source2.vala -o my-program


Best regards,

Frederik
_______________________________________________
Vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to