Re: [Vala] Generating vapi file for a simple struct





2009/5/18 Jan-Jaap van der Geer <jjvdgeer inbox com>
Matías De la Puente <mfpuente.ar@gmail.com> wrote:

> > Is there any need for the cprefix and clower_case_prefix in
> > this case? I get the impression that they are not used as long
> > as I specify the cname itself.

> There's no need to add cprefix in this case. cprefix and
> lower_case_cprefix (this is the real name) is used to give to the
> members some prefix and they only needed when there's some common
> prefix between the members. In this case you can make
> lower_case_cprefix="err" and define the members as num and mess.
> Try both i use cprefix in enums and lower_case_cprefix in classes
> and namespaces..

I understand.

I am trying to find out what the best way is to "vapify" this
library. There are some naming conventions which are OK within C,
but I would like to go for a more CamelCase style within Vala.

There are some enum-type things defined like this:

typedef bits wimp_error_box_flags;

#define wimp_ERROR_BOX_OK_ICON          ((wimp_error_box_flags) 0x1u)
#define wimp_ERROR_BOX_CANCEL_ICON      ((wimp_error_box_flags) 0x2u)
#define wimp_ERROR_BOX_HIGHLIGHT_CANCEL ((wimp_error_box_flags) 0x4u)

I made these into an enum like this:

public enum ErrorBoxFlags
{
 [CCode (cname = "wimp_ERROR_BOX_OK_ICON")]
 OKIcon = 0x01,
 [CCode (cname = "wimp_ERROR_BOX_CANCEL_ICON")]
 CancelIcon = 0x02,
 [CCode (cname = "wimp_ERROR_BOX_HIGHLIGHT_CANCEL")]
 HighlightCancel = 0x04,
}

Would it be possible to do this somewhat more like this?

[CCode (cprefix = "wimp_ERROR_BOX_")]
public enum ErrorBoxFlags
{
 [CCode (member = "OK_ICON")]
 OKIcon = 0x01,
 [CCode (member = "CANCEL_ICON")]
 CancelIcon = 0x02,
 [CCode (member = "HIGHLIGHT_CANCEL")]
 HighlightCancel = 0x04,
}

(where "member" is something I invented)

Is something like this possible? It would make it a bit more
readable. But maybe there is no point in that for a vapi-file?

Cheers,
Jan-Jaap
_______________________________________________
Vala-list mailing list
Vala-list gnome org
http://mail.gnome.org/mailman/listinfo/vala-list

I suggest to you this:

[CCode (cname="wimp_error_box_flags", cprefix="wimp_ERROR_BOX_")]
public enum ErrorBoxFlags
{
  OK_ICON,
  CANCEL_ICON,
  HIGHLIGHT_CANCEL
}

First of all, as you can see you don't need to put the constant value. Second don't try to use CamelCase in this situation because as you can see in others vapi files they don't use it.
Please take a look at this non-glib vapi files libusb.vapi and tiff.vapi, you can see how are written enums, compact objects, etc. They are in /usr/share/vala/vapi

Matias


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]