Re: [gtk-list] Re: Gtk and the scripting languages of the world
- From: Kenneth Albanowski <kjahds kjahds com>
- To: gtk-list redhat com
- Subject: Re: [gtk-list] Re: Gtk and the scripting languages of the world
- Date: Sat, 23 Aug 1997 15:42:41 -0400 (EDT)
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)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]