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

[PATCH] Add GType entries to Glib typemap



This patch provides the input and output rules to allow one to pass in or
return GType entries.  The patch works by using the package_from_type and
type_from_package methods to convert a package string into a type and vice
versa, so that the Perl representation of a GType is a package name.

Brett.
Index: typemap
===================================================================
RCS file: /cvsroot/gtk2-perl/gtk2-perl-xs/Glib/typemap,v
retrieving revision 1.9
diff -u -r1.9 typemap
--- typemap	5 Jul 2003 09:53:28 -0000	1.9
+++ typemap	14 Jul 2003 03:17:28 -0000
@@ -46,6 +46,8 @@
 gfloat		T_FLOAT
 gdouble		T_DOUBLE
 
+GType		T_G_TYPE
+
 GObject*	T_G_TYPE_OBJECT
 GObject_ornull*	T_G_TYPE_OBJECT_ORNULL
 GObject_noinc*	T_G_TYPE_OBJECT_NOINC
@@ -71,6 +73,16 @@
 	$var = ($type)SvPV ($arg, STRLEN_length_of_$var);
         XSauto_length_of_$var = STRLEN_length_of_$var;
 
+T_G_TYPE
+        {
+          GType type = gperl_object_type_from_package((gchar *)SvPV_nolen($arg));
+
+          if (type == 0)
+            croak(\"The package %s has not been register with Glib\", SvPV_nolen($arg));
+          else
+            $var = type;
+        }
+
 T_G_TYPE_OBJECT
 	$var = SvGObject ($arg);
 
@@ -109,6 +121,23 @@
 	sv_setpv ((SV*)$arg, $var);
 	SvUTF8_on ($arg);
         g_free ($var);
+
+T_G_TYPE
+        {
+          gchar *tmp = gperl_object_package_from_type($var);
+
+          if (tmp != NULL)
+            {
+              sv_setpv((SV *)$arg, tmp);
+              SvUTF8_on($arg);
+            }
+          else
+	    {
+	      warn(\"Function tried to return an unregistered type\");
+
+              $arg = newSVsv(&PL_sv_undef);
+	    }
+        }                  
 
 T_G_TYPE_OBJECT
 	$arg = newSVGObject ($var);


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