[perl-Glib-Object-Introspection] Allow enums and flags to have class functions



commit 9e214e19daa68e72b2bca38f7f09347e25880e13
Author: Torsten SchÃnfeld <kaffeetisch gmx de>
Date:   Mon Jan 28 00:05:11 2013 +0100

    Allow enums and flags to have class functions

 GObjectIntrospection.xs |    4 +++-
 NEWS                    |    1 +
 gperl-i11n-info.c       |   22 ++++++++++++++++++++++
 gperl-i11n-method.c     |    7 +++++++
 4 files changed, 33 insertions(+), 1 deletions(-)
---
diff --git a/GObjectIntrospection.xs b/GObjectIntrospection.xs
index c38475f..23cc7c8 100644
--- a/GObjectIntrospection.xs
+++ b/GObjectIntrospection.xs
@@ -366,7 +366,9 @@ _register_types (class, namespace, package)
 		    info_type == GI_INFO_TYPE_INTERFACE ||
 		    info_type == GI_INFO_TYPE_BOXED ||
 		    info_type == GI_INFO_TYPE_STRUCT ||
-		    info_type == GI_INFO_TYPE_UNION)
+		    info_type == GI_INFO_TYPE_UNION ||
+		    info_type == GI_INFO_TYPE_ENUM ||
+		    info_type == GI_INFO_TYPE_FLAGS)
 		{
 			store_methods (namespaced_functions, info, info_type);
 		}
diff --git a/NEWS b/NEWS
index ab225b2..3704af2 100644
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,7 @@ Overview of changes in Glib::Object::Introspection <next>
 * Correctly marshal out/in-out args when invoking Perl code and fix some other
   related bugs.  This makes it possible to implement complicated interfaces
   such as Gtk3::TreeModel.
+* Allow enums and flags to have class functions.
 * Plug a few memory leaks.
 
 Overview of changes in Glib::Object::Introspection 0.013
diff --git a/gperl-i11n-info.c b/gperl-i11n-info.c
index 3fc26a2..42c8752 100644
--- a/gperl-i11n-info.c
+++ b/gperl-i11n-info.c
@@ -1,5 +1,21 @@
 /* -*- mode: c; indent-tabs-mode: t; c-basic-offset: 8; -*- */
 
+static GIFunctionInfo *
+_find_enum_method (GIEnumInfo *info, const gchar *method)
+{
+	gint n_methods;
+	gint i;
+	n_methods = g_enum_info_get_n_methods (info);
+	for (i = 0; i < n_methods; i++) {
+		GIFunctionInfo *method_info =
+			g_enum_info_get_method (info, i);
+		if (strEQ (g_base_info_get_name (method_info), method))
+			return method_info;
+		g_base_info_unref (method_info);
+	}
+	return NULL;
+}
+
 /* Caller owns return value */
 static GIFunctionInfo *
 get_function_info (GIRepository *repository,
@@ -39,6 +55,12 @@ get_function_info (GIRepository *repository,
 				(GIUnionInfo *) namespace_info,
 				method);
 			break;
+		    case GI_INFO_TYPE_ENUM:
+		    case GI_INFO_TYPE_FLAGS:
+			function_info = _find_enum_method (
+				(GIEnumInfo *) namespace_info,
+				method);
+			break;
 		    default:
 			ccroak ("Base info for namespace %s has incorrect type",
 			       namespace);
diff --git a/gperl-i11n-method.c b/gperl-i11n-method.c
index 1e9d0c8..639d050 100644
--- a/gperl-i11n-method.c
+++ b/gperl-i11n-method.c
@@ -46,6 +46,13 @@ store_methods (HV *namespaced_functions, GIBaseInfo *info, GIInfoType info_type)
 		break;
 	    }
 
+	    case GI_INFO_TYPE_ENUM:
+	    case GI_INFO_TYPE_FLAGS:
+	    {
+		PUSH_METHODS (enum, av, info);
+		break;
+	    }
+
 	    default:
 		ccroak ("store_methods: unsupported info type %d", info_type);
 	}



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