On Fri, Mar 4, 2011 at 6:15 PM, Luca Dionisi <[email protected]> wrote:
[...]
> We have a library with these sources:
> libfoo.c [http://pastebin.com/kDtaCR6Q]
> libfoo.h [http://pastebin.com/aDa3VEWt]
>
[...]
> Now I would like to use the library in vala with an interface like this:
> test_foo.vala [http://pastebin.com/qTAP9gqw]
> and I tried with the following vapi:
> libfoo.vapi [http://pastebin.com/bVnZU4NL]
>
> With this vapi the generated C file is the following:
> test_foo.c [http://pastebin.com/Lwu3JR8i]
>
> The difference with the first C file is that the variable that is used
> to carry a "Foo" object is of type foo_t*, while it should be a foo_t.
>
> What do I have to change in the vapi file to obtain a mapping more precise?
The problem is that you are using a typedef'd pointer. Is there any
reason you need to use this typedef within Vala? Since "foo_t" is just
an alias for "struct foo_st*", just set the cname for your Foo class
to "struct foo_st" instead of "foo_t". Vala will now output the
following:
void _vala_main (void) {
struct foo_st* x;
x = foo_new (3, 4);
fprintf (stdout, "%d\n", foo_sum (x));
_foo_destroy0 (x);
}
Which is just what your library expects, and I tried running this
code, and there are no compiler warnings and no errors:
$ valac --vapidir . --pkg foo -X -I. footest.vala libfoo.c
$ ./test
7
Hope that helps,
Alexander Krivács Schrøder
_______________________________________________
vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list