Re: [Vala] Variable sized structs and vapi files



On Tue, 2009-09-15 at 22:50 +0200, Jan Hudec wrote:
On Tue, Sep 15, 2009 at 20:33:03 +0200, Jan-Jaap van der Geer wrote:
On Tue, 2009-09-15 at 09:06 +0200, Jan Hudec wrote:
On Tue, September 15, 2009 00:09, Jan-Jaap van der Geer wrote:
    wimp_menu_entry_new(int n, wimp_menu_entry[] entries);
    ...
    [Compact]
    public class Menu {
        ...
        public Menu([CCode(array_length_pos = 0.9)] MenuEntry[] entries);
        ...

What does the array_length_pos = 0.9 mean?

Notice, that I wrote the C function with two arguments, but the vala with
only one. Arrays are normally passed as two arguments -- the pointer and the
size. And this attribute specifies at which position the additional argument
(size) goes.

When generating the argument list, vala compiler assigns each argument
a number. The declared arguments are number by whole numbers starting from
one, invocant (this) in method gets 0 and implicit parameters get just
a little bit higher number than the argument they accompany. Vala than emits
the arguments in order of that number.

So by specifying 0.9 I am saying the length of the array should go just
before the array pointer (which is argument 1.0), not after.

Ah, right, I understand now. Thanks!

... which really changes it to the next option. It depends on how convenient
you want to make the API in vala.

If you only specify length to the constructor, you will have to assign each
entry separately, so you will end up with a chain like

    menu.entries[0] = MenuEntry() { ... };
    menu.entries[1] = MenuEntry() { ... };

No other option would work, because the other array operations (like
assignment of whole array) depend on vala being able to reallocate the array
and to know it's length, neither of which is allowed by the underlying data
structure.

On the other hand if you specify the whole content, you will be able to
construct with single big constructor expression. Along the lines of:

    menu = new Menu(320, 240, new MenuEntry[] {
        { ... }, { ... }, ... });

(I've added the dimensions here -- you would want to specify all member
values as constructor arguments if you specify any for the API to make sense)

Yes, I see your point. I'll have to think about this one. The .vapi
files I have are all generated from files that describe the API using a
tool that generates assembly headers, C headers, C++ headers and
documentation files. I enhanced this system to include generation of
vapi files. So the above would mean I need to generate these
constructors and I am not really sure how practical that would be.

Related: Is there documentation about this? If so where can I find
that?
 
Very scarce. Look through the wiki, but mostly you will have to
look how similar things are done in the existing .vapi files.

Stupid question: What wiki are you talking about? I know about this
page, of course: http://live.gnome.org/Vala It looks somewhat wiki-ish,
but I'm not sure you're referring to that... Google didn't help me much.

BTW, on that page there is a link to "Hacker's Guide to Vala" which went
dead a few days ago.
 
I find it very difficult to look at other .vapi files as I have almost
no experience with GLIb and other libraries, coming from RISC OS where
these libraries are not generally used, or at the very least I am not
very familiar with them. So it is difficult for me to find relevant
comparable situations and their solutions in the .vapi files.

If you know at least the standard POSIX API, you can focus on the posix.vapi.
It does not use anything of glib.  It is actually possible to use vala
without glib altogether (using --profile=POSIX parameter), though many
features are not available than.

Not even that is familiar at this point :-| But the --profile=POSIX
intrigues me. What kind of things would not be available using this
POSIX profile?

Cheers,
Jan-Jaap





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