Re: [Vala] Array as big as an enum



----- Original Message -----

From: Evan Nemerson <evan coeus-group com>
Sent: Tuesday, 30 August 2016, 17:11
Subject: Re: [Vala] Array as big as an enum

On Mon, 2016-08-29 at 23:47 +0200, rastersoft wrote:
 Sorry, I found how to do that:

 int[] blah = new int[LAST_ELEMENT];

If you want to avoid having a LAST_ELEMENT value, something like this
will also work:

    ((GLib.EnumClass) typeof(Foo).class_ref ()).n_values

I'm not necessarily advocating it, but if you really want to keep your
API clean it's an option.



This gets the GType of Foo, instantiates it by increasing the ref count,
casts it to EnumClass and then uses the n_values field.

If someone was to add syntax support for this for both EnumClass and
FlagsClass, what would be the best way for this to look?

a) Explicit instantiation of the Foo EnumClass:

var a = new Foo ();
print ("%i", a.n_values);

b) Implicit access to EnumClass methods and fields:
print ("%i", Foo.v_values);



Opinions anyone?

Al


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