On Jun 5, 2007, at 1:38 PM, Johan Dahlin wrote:

> Tristan Van Berkom wrote:
>> On Mon, 2007-06-04 at 16:04 -0300, Johan Dahlin wrote:
> [..]
>> One thing that might or might not be a can of worms is
>> language bindings. I wonder if someone more experienced
>> than myself in this realm could point out how we plan
>> to load widgets written in other languages from the GtkBuilder
>> perspective, namely how will we obtain the runtime GType of
>> the object from its name in the xml/glade file.
>
> Python avoids this by registering all the types as soon as you load  
> the
> bindings. However this is unfortunately memory wise and might be  
> changed
> in the future.

So, too, with Gtk2-Perl.  This happens so that the mapping between  
perl package names and C GTypes exists in time for perl code to  
instantiate the correct type.  (Perl developers don't use GTypes,  
they use package names, which are class names in Perl.)  This means  
that "use"ing a module can trigger a series of gperl_register_type 
(gtype, package_name) calls; since you're passing in the GType, you  
will have registered the class already.

For all Perl-derived GObjects, the GType registration is handled by a  
single entry point, Glib::Type::register_object().  This usually  
happens at a user level from the Glib::Object::Subclass pragmatic  
module, which means that the registration happens as part of the  
parsing the Perl source.

There *is* a C function in the binding to fetch the GType  
corresponding to a perl package name: gperl_type_from_package().  So,  
given

      package CoolStuff::Window;
      use Gtk2;
      use Glib::Object::Subclass
          'Gtk2::Window',
          properties => [ ... ],
          signals => { ... },
          interfaces => [ ... ],
          ;

then this works:

     #include <gperl.h>

     gtype = gperl_type_from_package ("CoolStuff::Window");
     object = g_object_new (gtype, ...);

*provided* that the perl code defining package CoolStuff::Window has  
already been parsed and executed.


If you wanted to have an automatic lookup of whatever_get_type()  
functions, we'd have to add to the bindings functions which would  
ensure that the interpreter is loaded and that module has been  
parsed, and then ask for the gtype.  My gut tells me that another  
solution exists, but i don't know what it is.



--
I hate to break it to you, but magic data pixies don't exist.
   -- Simon Cozens


_______________________________________________
gtk-devel-list mailing list
gtk-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-devel-list

Reply via email to