Re: [Vala] How to properly define struct in manually written VAPI?
- From: Al Thomas <astavale yahoo co uk>
- To: "marcin saepia net" <marcin saepia net>, vala <vala-list gnome org>
- Subject: Re: [Vala] How to properly define struct in manually written VAPI?
- Date: Wed, 2 Mar 2016 11:54:02 +0000 (UTC)
From: "marcin saepia net" <marcin saepia net>
Sent: Wednesday, 2 March 2016, 10:19
Subject: [Vala] How to properly define struct in manually written VAPI?
I need to write VAPI for jansson JSON library. I have already started (
https://github.com/akheron/jansson/pull/273) and generally speaking it
works fine but I have an issue with covering one struct.
In C code there's the following struct:
#define JSON_ERROR_TEXT_LENGTH 160
#define JSON_ERROR_SOURCE_LENGTH 80
Bind as:[CCode (cname = "int", cprefix = "JSON_ERROR_", has_type_id = false)]
public enum JsonErrorLengths {
TEXT_LENGTH,
SOURCE_LENGTH
}See: https://wiki.gnome.org/Projects/Vala/LegacyBindings#Enums_and_Flags
typedef struct {
int line;
int column;
int position;
char source[JSON_ERROR_SOURCE_LENGTH];
char text[JSON_ERROR_TEXT_LENGTH];
} json_error_t;
Try binding as:[CCode( cname = "json_error_t", has_type_id = false )]public struct JsonError { public int
line; public int column; public int position; public uint8 source[ JsonErrorLengths.SOURCE_LENGTH ];
public uint8 text[ JsonErrorLengths.TEXT_LENGTH ];
}
or you could try using:[CCode (array_length_cexpr = "JSON_ERROR_SOURCE_LENGTH")]See:
https://wiki.gnome.org/Projects/Vala/LegacyBindings#Arrays-1
I hope that helps,
Al
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]