Re: [Vala] Access the "klass" parameter of a class_init() function in vala with "static construct"



On Sat, 2010-07-31 at 22:08 +0200, Sébastien Wilmet wrote:


2010/7/31 Evan Nemerson <evan coeus-group com>
        On Sat, 2010-07-31 at 17:59 +0200, Sébastien Wilmet wrote:
        > Hello!
        >
        > What I want to do is to implement a GtkAction derived class
        which sets
        > GtkActionClass:toolbar_item_type to
        GTK_TYPE_MENU_TOOL_BUTTON in its
        > class_init function.
        
        
        Vala doesn't currently expose *Class structs in the bindings,
        so AFAIK
        what you're talking about can't be done easily. I'm not
        exactly an
        expert on GObject, but I think you should be able to hack
        something
        together by going creating bindings for GtkActionClass then
        getting
        access to it with GLib.Object.get_class. This is untested, but
        you
        should get the idea:
        
        
        /* In a vapi */
        [Compact, CCode (cname = "GtkActionClass")]
        public class GtkActionClass {
         public GLib.Type menu_item_type;
         public GLib.Type toolbar_item_type;
        }
        
        /* Your code */
        unowned GtkActionClass ac = (GtkActionClass) this.get_class
        ();
        ac.toolbar_item_type = typeof (MenuToolButton);
        

I have this error:
error: Access to instance member `GLib.Object.get_class' denied

You aren't going to be able to access it from a static construct block.
Try it from within a regular construct block.


Also, in C the cast can be made because the first field in a Class
struct is the parent class.

That doesn't really solve anything, since you don't have access to the
instance from within a static constructor (hence the error about access
to an *instance member* being denied). Whether you just cast or use the
G_OBJECT_CLASS macro, you still need an instance.


-Evan




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