[Vala] Need help to make binding for typedef'd pointer struct
- From: Ahmad Syukri bin Abdollah <syockit gmail com>
- To: vala-list gnome org
- Subject: [Vala] Need help to make binding for typedef'd pointer struct
- Date: Wed, 03 Oct 2012 12:06:41 -0000
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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]