Re: [Vala] How to set the type of the elements in a container on bindings.



On Wed, 2012-05-16 at 15:28 +0200, Alejandro T. Colombini wrote:
Hello vala-list,
  I'm generating a Vala binding for a C library using vapigen and I've
managed to set the type of the elements by using the GObject
Introspection's "element-type" annotation for both the parameters and
return values of functions, but now I need a way to do the same thing for
the element type of object memebers.

  A simple example of what I want:
public class MyObject : GLib.Object{
    public weak GLib.SList<AnotherObject> object_list;
}

  And this is what I've generated so far:
public class MyObject : GLib.Object{
    public weak GLib.SList<void*> object_list;
}

  I've taken a look at the GIDL metadata and also the GObject
Instrospection documentations, but i've found nothing that suits my needs.
If there's still no way (or will never be) to do this, I guess there's no
problem leaving the element type as "void*" in the generated .vapi files.

GIDL is not the same as GIR (which is the XML format used by GObject
Introspection).  You could use GIR metadata to achieve what you're
after:

        MyObject.object_list type="weak GLib.SList<AnotherObject>"

If you really did mean GIDL you could do something like this:

        MyObject.object_list type_arguments="AnotherObject"

But if you're really using G-I it would be best to add the proper
annotations to your C code so other G-I consumers can take advantage.  I
believe something like this should work:

        /**
         * MyObject:
         * @object_list: (element-type AnotherObject): list of objects
         *
         * Description of MyObject.
         */
        typedef struct _MyObject {
          GSList* object_list;
        } MyObject;


-Evan




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