Re: [Vala] Array as big as an enum
- From: Andy Lees <andrewl oz gmail com>
- To: rastersoft <raster rastersoft com>
- Cc: Vala List <vala-list gnome org>
- Subject: Re: [Vala] Array as big as an enum
- Date: Thu, 1 Sep 2016 07:16:35 +1000
You can access them as strings: Foo.ELEMENT.to_string() (or any Foo-typed
expression). The default result may be a bit clunky, but very useful
nevertheless. Add you own to_string if you want to get fancy.
On Thu, Sep 1, 2016 at 3:51 AM, rastersoft <raster rastersoft com> wrote:
El 31/08/16 a las 17:20, Al Thomas escribió:
----- 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);
The B one sounds better, I think. Even more: it would be great to be
able to access to the enums as strings too.
--
Nos leemos
RASTER (Linux user #228804)
raster rastersoft com http://www.rastersoft.com
_______________________________________________
vala-list mailing list
vala-list gnome org
https://mail.gnome.org/mailman/listinfo/vala-list
[
Date Prev][Date Next] [
Thread Prev][Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]