Re: rework of the Gtk2-Perl type system



On fre, 2003-03-21 at 03:52, muppet wrote:
As i have mentioned before and you are probably sick of hearing, i have
an independent, GObject-based C library that i wish to bind to perl in
such a way that i can use its objects seamlessly with gtk objects, e.g.,
binding callbacks and packing my library's widgets into windows and
other normal gobject/gtk things, similar to how the Gnome2 package
works.

I'm hoping to wrap Evolutions CalClient once gtk2 evolution is stable
enough for everyday use (it may be already - but thats not the).
So I'd really like to see something like this.

[massive snipage]

I propose something like

   void gtk2_perl_register_class_mapping (const char * class,
                                          const char * package,
                                          gboolean require);

Using a string for the class name instead of a GType allows us to
specify mappings for non GObject types (structs and boxed types).  The
"require" parameter lets you specify whether the class has a pm that
must be loaded.

This fills the requirements I can imagine, at the moment.

For simplicity, i imagine the class mappings as being one-to-one:

   GtkWidget <=> Gtk2::Widget
   GdkWindow <=> Gtk2::Gdk::Window
   GdkEventKey <=> Gtk2::Gdk::Event::Key
   PangoFontDescription <=> Gtk2::Pango::FontDescription
   GnomeAbout <=> Gnome2::About
   MylibFooBar <=> Mylib::FooBar

With one-to-one mappings, get_class_from_classname could return a
pointer that need not be freed, and thus avoid memory leaks.

On the other hand, it might also be possible to do something like

   void gtk2_perl_register_class_mapping_rule (char * perl_code_to_eval)

which would allow you somehow to specify a substitution pattern for a
whole set of mappings, to be run as a code reference, and successful
results cached to avoid running it again.  I am willing to implement
this, but i want help designing that portion of the interface.

This would be very Perl'ish, but I don't see an immediate need for it.

get_class and get_class_from_classname should be renamed to avoid both
symbol clashes (the module must be loaded with RTLD_GLOBAL!) and the
confusion of calling everything classes.  i propose:

  char * gtk2_perl_get_package_from_gobject (GObject *)
  char * gtk2_perl_get_package_from_gtype (GType)
  char * gtk2_perl_get_package_from_classname (char *)
     retrieve package names

  GType gtk2_perl_get_type_from_package (char *)
  char * gtk2_perl_get_classname_from_package (char *)
     the other way 'round

Your proposal seems sound to me.
Could get_class and get_class_from_classname not be kept as defines, to
let the existing code live on?

Also, we could let the GType system do a lot of work for us by
implementing @ISA as a tied variable which uses
gtk2_perl_get_package_from_class, g_type_parent, and
g_type_get_class_from_package.

Sounds cool.
How would it perform? 
And would it mess up the optimisations of method lookups? I assume not
as the mappings should be pretty much stable. 
Not sure how it would work though (which @ISA should be tied), have you
got any examples of modules doing this?  

Sorry for the late reply.

./borup




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