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)))

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/     17 Oct 2002 09:04:50 -0000      1.2
+++ Gtk2/     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
+++ 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)
-    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);
     return data;

And, the important part, the following new files:

Description: ./

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

- 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 might be better in a "tools" subdir, this
  directory supposed to grow later?
- the 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 -

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