Re: [Vala] embedding c code snippet in vala source.



Hi Yu,

On Fri, 2008-08-22 at 02:58 -0400, Yu Feng wrote:
Which do you prefer if you want to split a string? mysplit or split?

    [CCode (cname = "g_strmysplit", snippet = "gchar ** rt = g_strsplit(this,
delimiter, max_tokens); *result_length1 = rt?g_strv_length(rt):0; return rt;")]
    public string[] mysplit (string delimiter, int max_tokens = 0);

    [CCode (cname = "g_strsplit")]
    [NoArrayLength]
    public string[] split (string delimiter, int max_tokens = 0);

While mysplit is more comfortable to use right now as it correctly
handles the null-terminated array, reading C code snippets embedded into
a string in a .vapi file is not what I'm looking forward to.

Support for null-terminated arrays is planned, so the second split
binding will work the same way without major additions in the .vapi file
as soon as this is implemented.

As far as I understand it, you're proposing to not handle this at all in
the compiler and just add a snippet attribute to any function that
doesn't conform exactly to the default translation. While this would
probably make it possible to drop some other attributes, reading and
writing bindings like this would be a major pain.

I don't want to have dozens of g_strv_length calls in my .vapi file if I
can fix this just once in the compiler. Also, this would require a lot
more complicated metadata for generated bindings.

Maybe I'm just missing an interesting use case, however, I currently
fail to see where the snippet approach makes it more comfortable to
write or use bindings. Can you provide examples where you think that it
makes more sense to handle it in a snippet instead of the compiler code?
I'm not convinced by the g_strv_length example as this would clutter the
bindings too much, in my opinion.

Jürg





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