Re: [Vala] VAPI-Bindings to obscure c-types.
- From: Guillaume Poirier-Morency <guillaumepoiriermorency gmail com>
- To: Al Thomas <astavale yahoo co uk>
- Cc: Daniel Brendle <grindhold skarphed org>, vala-list <vala-list gnome org>
- Subject: Re: [Vala] VAPI-Bindings to obscure c-types.
- Date: Mon, 5 Dec 2016 12:30:36 -0500
You could also use a [FloatingType] declaration and not mess with
pre-processor directives.
[FloatingType]
public struct dReal {}
2016-12-05 7:20 GMT-05:00 Al Thomas via vala-list <vala-list gnome org>:
----- Original Message -----
From: Daniel Brendle <grindhold skarphed org>
Sent: Monday, 5 December 2016, 7:53
Subject: [Vala] VAPI-Bindings to obscure c-types.
In libode's code, there is a type called dReal. Depending on some
compiler flags, dReal might be a double or a float:
#if defined(dSINGLE)
typedef float dReal;
#ifdef dDOUBLE
#error You can only #define dSINGLE or dDOUBLE, not both.
#endif /* dDOUBLE */
#elif defined(dDOUBLE)
typedef double dReal;
#else
#error You must #define dSINGLE or dDOUBLE
#endif
The library then uses dReal in various method signatures that I have to
bind against. Is there any possibility to cover this in vala?
These are macros that are defined without a value and are used by the C
pre-processor. To define such a macro from valac, as you probably know, you
use the -X option:
valac --pkg libode6 -X -DdDOUBLE example.vala
Vala has a similiar, but much simpler, pre-processor:
https://wiki.gnome.org/Projects/Vala/Manual/Preprocessor
https://wiki.gnome.org/Projects/Vala/ConditionalCompilationSample
The Vala pre-processor can also be used in a VAPI file:
#if ODE_FLOAT
[SimpleType]
[CCode (cname = "dReal", has_type_id = false)]
public struct dReal : float {
}
#else
[SimpleType]
[CCode (cname = "dReal", has_type_id = false)]
public struct dReal : double {
}
#endif
So for double you would compile with:
valac --pkg libode6 -X -DdDOUBLE example.vala
and for float:
valac --pkg libode6 -X -DdSINGLE -D ODE_FLOAT example.vala
You will have to use separate declarations for both the C pre-processor
and the Vala pre-processor. While you can define a macro in a .vala file by
using const, this cannot currently be emitted before the #include in the
generated C file. So it is not set at the time when the C header is
processed.
This is untested and probably doesn't reflect your binding, but should
convey the method.
Al
_______________________________________________
vala-list mailing list
vala-list gnome org
https://mail.gnome.org/mailman/listinfo/vala-list
--
Guillaume Poirier-Morency <guillaumepoiriermorency gmail com>
Étudiant au baccalauréat en Informatique à l'Université de Montréal
Développeur d'application web
*Mon blog:* arteymix.github.io
*Mon projet de coopérative:* pittoresque.github.io
*Clé PGP:* B1AD6EA5
<https://pgp.mit.edu/pks/lookup?op=vindex&search=0x1CCFC3A2B1AD6EA5>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]