Re: [Vala] Need help to make binding for typedef'd pointer struct
- From: Jonas Kulla <nyocurio gmail com>
- To: vala-list gnome org
- Subject: Re: [Vala] Need help to make binding for typedef'd pointer struct
- Date: Fri, 19 Oct 2012 20:58:29 +0200
2012/10/3 Ahmad Syukri bin Abdollah <syockit gmail com>
Greetings!
Not long ago, someone made a binding for GMP
(https://mail.gnome.org/archives/vala-list/2011-August/msg00048.html)
and posted it on the wiki, but it seems to have been lost.
I'm attempting to write a new one, but came across some design
difficulties.
In the original API, the custom number types are structs. To use them,
they are allocated, initialized, and passed to API functions via its
pointer.
{snip: C example}
/* declare var using mpz_t, which is typedef'd to the length-1 array
of the struct */
mpz_t num1, num2;
/* initialize */
mpz_init_set_ui(num1, 1495);
mpz_init_set_si(num2, -30);
/* do operations */
mpz_add(num2, num1, num2);
I managed to conjure a simple binding using struct to interface the
original struct, since you can't typedef a pointer struct in Vala.
But then the usage will look like this:
{snip: Vala exampe}
mpz_t num1, num2;
mpz.init_set_ui(out num1, 1495);
mpz.init_set_ui(out num2, 1495);
mpz_add(&num2, &num1, &num2);
// or maybe: mpz_add(out num2, out num1, out num2);
If possible I'd like to avoid having to use ref/out/&. A compact class
seems to be a good substitute, since they are passed by reference by
default.
The problem is, class needs a "new" function, which doesn't exist in
the API (because the types designed as objects).
Can I define what the new function does without having to include an
extra header file?
Regards,
A. Syukri
Hi!
I think I had a similar problem to yours when writing a vapi for the
popular minizip utilities.
What they did was typedef a void pointer to an opaque type, which was
passed by value,
and it seems to me from the C code you provided that it's the same case
here as well(?).
Anyway, what I did was simply declare the type as a [SimpleType] struct (no
pun intended).
This solution isn't perfect, but it worked for me.
- Jonas
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]