enum/flags list_values values



Is Glib::Type->list_values meant to give back the values from the enum
and flags entries, as well as the names?  (There's no significance in
the order of the returned list or anything, is there.)

--- GType.xs    10 Dec 2007 07:46:30 +1100      1.81
+++ GType.xs    05 Jan 2008 07:41:53 +1100      
@@ -2566,7 +2566,12 @@
 this function will croak.
 
 Returns the values as a list of hashes, one hash for each value, containing
-that value's name and nickname.
+the value, name and nickname, eg. for Glib::SignalFlags
+
+    { value => 8,
+      name  => 'G_SIGNAL_NO_RECURSE',
+      nick  => 'no-recurse'
+    }
 
 =cut
 void
@@ -2581,15 +2586,15 @@
                croak ("%s is not registered with either GPerl or GLib",
                       package);
        /*
-        * unfortunately, GFlagsValue and GEnumValue different structures
-        * that happen to have identical definitions, so even though it
-        * is very inviting to use the same code for them, it's not
-        * technically a good idea.
+        * GFlagsValue and GEnumValue are nearly the same, but differ in
+        * that GFlagsValue is a guint for the value, but GEnumValue is gint
+        * (and some enums do indeed use negatives, eg. GtkResponseType).
         */
        if (G_TYPE_IS_ENUM (type)) {
                GEnumValue * v = gperl_type_enum_get_values (type);
                for ( ; v && v->value_nick && v->value_name ; v++) {
                        HV * hv = newHV ();
+                       hv_store (hv, "value",5, newSViv (v->value), 0);
                        hv_store (hv, "nick", 4, newSVpv (v->value_nick, 0), 0);
                        hv_store (hv, "name", 4, newSVpv (v->value_name, 0), 0);
                        XPUSHs (sv_2mortal (newRV_noinc ((SV*)hv)));
@@ -2598,6 +2603,7 @@
                GFlagsValue * v = gperl_type_flags_get_values (type);
                for ( ; v && v->value_nick && v->value_name ; v++) {
                        HV * hv = newHV ();
+                       hv_store (hv, "value",5, newSVuv (v->value), 0);
                        hv_store (hv, "nick", 4, newSVpv (v->value_nick, 0), 0);
                        hv_store (hv, "name", 4, newSVpv (v->value_name, 0), 0);
                        XPUSHs (sv_2mortal (newRV_noinc ((SV*)hv)));


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