[810] in The GTK GIMP ToolKit mailing list archive

home help back first fref pref prev next nref lref last post

[gtk-list] Re: Gtk and the scripting languages of the world

daemon@ATHENA.MIT.EDU (Kenneth Albanowski)
Sat Aug 23 15:42:50 1997

Date: Sat, 23 Aug 1997 15:42:41 -0400 (EDT)
From: Kenneth Albanowski <kjahds@kjahds.com>
To: gtk-list@redhat.com
In-Reply-To: <87yb5srat9.fsf@zagadka.ping.de>
Resent-From: gtk-list@redhat.com
Reply-To: gtk-list@redhat.com

On 23 Aug 1997, Marius Vollmer wrote:

> Then we can't use them.  But the gtk_object_set_data/get_data
> mechanism can work with types, I think.

Oh yes. Here's a sample from Gtk. (Which _still_ isn't on CPAN. I think
Andreas is at perlcon in SJ, at the moment, or coming back from it.)

This code only deals with GtkObject types at the moment, but it would be
easy to extend it. However, it does have the same limitation as other
places: there is no way to tell when the user data is deleted if Gtk does
it itself, so the perl reference leaks.

void
set_user_data(object, data)
        Gtk::Object     object
        SV *    data
        CODE:
        {
           if (!data || !SvOK(data)) {
               gtk_object_set_user_data(object, 0);
               gtk_object_set_data(object, "user_data_type_Perl",0);
           } else {
               int type=0;
               gpointer ptr=0;
               if (SvRV(data)) {
                  if (sv_derived_from(data, "Gtk::Object")) {
                     type = 1;
                     ptr = SvGtkObjectRef(data, 0);
                  }
               }
               if (!type)
                  croak("Unable to store user data of that type");
               gtk_object_set_user_data(object, ptr);
               gtk_object_set_data(object, "user_data_type_Perl", (gpointer)type);
          }
       }


-- 
Kenneth Albanowski (kjahds@kjahds.com, CIS: 70705,126)


--
To unsubscribe: mail -s unsubscribe gtk-list-request@redhat.com < /dev/null


home help back first fref pref prev next nref lref last post