Re: gtk2-perl / casting from perl objects to gtk objects



goran kirra net writes:

On Thu, Oct 17, 2002 at 12:44:25PM +0200, Guillaume Cottenceau wrote:
#define pGtkWidget(o) ((GtkWidget*) SvIV(SvRV(o)))
#define pGtkProgressBar(o) ((GtkProgressBar*) SvIV(SvRV(o)))

sure,
but you have to figure out where to put it
so it can be included at compile time without 
to much trouble.
Perhaps a include directory in the root which is
added to the INC config entry.

Here it is; the INC mechanism is pretty dirty but I don't really
know well how to do better (having a $toplevel variable would be
nice for example?).

There is the following patch for one initial C file:

--- Gtk2/GObject.pm     17 Oct 2002 09:04:50 -0000      1.2
+++ Gtk2/GObject.pm     17 Oct 2002 13:21:43 -0000
@@ -14,7 +14,7 @@
   PREFIX => 'gperl_object_',
   LIBS => `pkg-config gtk+-2.0 --libs`,
   OPTIMIZE => '-g',
-  INC => `pkg-config gtk+-2.0 --cflags`;
+  INC => '-I../../../../Gtk2/include '.`pkg-config gtk+-2.0 --cflags`;
 
 
 sub set_data
--- Gtk2/src/GObject.c  15 Oct 2002 21:00:49 -0000      1.1.1.1
+++ Gtk2/src/GObject.c  17 Oct 2002 13:21:43 -0000
@@ -5,17 +5,17 @@
  */
 
 #include <glib-object.h>
-
+#include "gtk2-perl-helpers.h"
 
 void gperl_object_set_data1(SV* object, char* key, SV* data)
 {
     SvREFCNT_inc(data);
-    g_object_set_data((GObject*) SvIV(SvRV(object)), key, data);
+    g_object_set_data(pGObject (object), key, data);
 }
 
 SV* gperl_object_get_data1(SV* object, char* key)
 {
-    SV* data = (SV*) g_object_get_data((GObject*) SvIV(SvRV(object)), key);
+    SV* data = (SV*) g_object_get_data(pGObject(object), key);
     SvREFCNT_inc(data);
     return data;
 }


And, the important part, the following new files:

Attachment: autogen.pl
Description: ./autogen.pl

Attachment: gtk2-perl-helpers.h
Description: Gtk2/include/gtk2-perl-helpers.h


Notes:
- since these are new files, I've put an initial copyright with
  my name, as it's usually done :) but it may change in the
  future anyway
- the autogen.pl might be better in a "tools" subdir, this
  directory supposed to grow later?
- the autogen.pl is itself supposed to eventually grow if we need
  more autogeneration of macros or whatever, hence the use of
  @autogen added over in the file
- I've made things so that C files would include
  gtk2-perl-helpers.h rather than the autogenerated header, since
  it might grow with additions by hand, later on


If you're happy with that, I will try to convert the whole code
to the macros, and submit the patch to you.


-- 
Guillaume Cottenceau - http://people.mandrakesoft.com/~gc/


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