Some errors were bogus because I had cut a "construct" line out of my
report; however I think I am OK here:

public class PhoneUIGlade : Gtk.Object {
    protected Glade.XML xml;
    private Module module;
    protected class window_widgets {
    Gtk.Widget blah;
    Gtk.Widget blah2;
    }
    protected window_widgets widgets;
}

by declaring a class instead of a struct.

I really wanted an anonymous struct though, but it seems that vala
forbids that.

At least with a class (done as a pointer, so no "incomplete type"
errors) the memory isn't allocated till it's used.

So now I just need to work around the union problem, maybe just
typecasting the address of widgets as a *Gtk.Widget and array offsetting
will get round it.

Sam


* Sam Liddicott wrote, On 23/06/08 12:36:
> I'm playing around trying to implement some C structures neatly in vala
> and come over these strange situtions.
>
> Case 1
>
>   protected struct widgets {
>     Gtk.Widget blah;
>     Gtk.Widget blah2;
>     }
>
> public class PhoneUIGlade : Gtk.Object {
>     protected Glade.XML xml;
>     protected widgets widgets;
>     private Module module;
> }
>
> src/phoneui.glade.vala:35.15-35.21: error: `PhoneUIGlade.widgets' is not
> a type
>     protected widgets widgets;
>               ^^^^^^^
> Compilation failed: 1 error(s), 0 warning(s)
>
>
> How was I supposed to refer to the outer struct type?
>
>
> Case 2
>
> public class PhoneUIGlade : Gtk.Object {
>     protected Glade.XML xml;
>     protected struct widgets {
>       Gtk.Widget blah;
>       Gtk.Widget blah2;
>     } protected widgets x;
>     private Module module;
> }
>
>
> (I call it x and not widgets otherwise I get
> "src/phoneui.glade.vala:34.7-34.32: error: `PhoneUIGlade' already
> contains a definition for `widgets'" even though one is a type and one
> is a variable and so should be in different compiler namespaces)
>
> In file included from ./src/mainwindow.h:30,
>                  from src/mainwindow.c:22:
> ./src/phoneui.glade.h:50: error: field ‘widgets’ has incomplete type
>
> the generated ./src/phoneui.glade.h has:
>
> ...
> typedef struct _PhoneUIGladewidgets PhoneUIGladewidgets;
>
> /*[CCode (cheader_filename="phoneui.glade.h")]*/
> struct _PhoneUIGlade {
>     GtkObject parent_instance;
>     PhoneUIGladePrivate * priv;
>     GladeXML* xml;
>     PhoneUIGladewidgets x;
> };
>
> ...
> struct _PhoneUIGladewidgets {
>     GtkWidget* blah;
>     GtkWidget* blah2;
> };
>
>
> So we see that the struct _PhoneUIGladewidgets is not defined until
> after class that holds and defines it _PhoneUIGlade.
>
>
> Case 3
>
> I can't get anything like this to compile in vala at all; please could
> someone give me a clue.
> I'm trying to define a protected type in an automatically generated
> superclass of a glade window, so the manually generated subclass gets
> delphi-like access to all the widgets.
>
> union widgets {
>   Gtk.Widget by_number[window1_WIDGET_COUNT];
>   struct by_name {
>     Gtk.Window window1; /* GtkWindow window1 */
>     Gtk.VBox vbox1; /* GtkVBox vbox1 */
>     Gtk.Image image1; /* GtkImage image1 */
>     Gtk.Button button1; /* GtkButton button1 */
>     Gtk.Statusbar statusbar1; /* GtkStatusbar statusbar1 */
>   }
> };/* widget name list for runtime binding */
>
>
> Sam
>
> _______________________________________________
> Vala-list mailing list
> [email protected]
> http://mail.gnome.org/mailman/listinfo/vala-list
>   


_______________________________________________
Vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to