Re: [Vala] Compact class with an unusual (in GLib terms) constructor
- From: Al Thomas <astavale yahoo co uk>
- To: Gergely Polonkai <gergely polonkai eu>, Vala <vala-list gnome org>
- Subject: Re: [Vala] Compact class with an unusual (in GLib terms) constructor
- Date: Wed, 5 Apr 2017 15:59:37 +0000 (UTC)
From: Gergely Polonkai <gergely polonkai eu>
Sent: Wednesday, 5 April 2017, 16:39
Subject: [Vala] Compact class with an unusual (in GLib terms) constructor
libjwt[1] has a strange constructor in GLib terms:
int jwt_new(jwt_t **jwt);
It returns 0 on success (like many C functions) or any valid errno on
failure. I made the following binding for now:
[CCode (cname = "jwt_new")]
public static int create(out JWT jwt);
Is there a better way to do this?
These kind of constructors are fairly common in the C world and I
think there should be a more Valaesque way of binding them using
a Vala constructor that throws an error.
This is only a theory and may not work. I will try playing around
with it myself at some time, but the approach I have in mind is:
1. Bind errno as an errordomain instead of an enum, not tried to see
if that is possible. Also be aware enums can't have values given
in the VAPI. The values have to be defined externally in the C header
2. Bind jwt_new as a private function
3. A function in a VAPI can have a body, so create a Vala constructor
as for a normal class that can throw the errordomain
4. Then add logic to the constructor that checks the return value
of jwt_new and either sets this to the instance or throws the
errordomain
Good luck!
Al
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]