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

Ali Sabil пишет:

On Fri, Aug 22, 2008 at 7:32 AM, Yu Feng <rainwoodman gmail com <mailto:rainwoodman gmail com>> wrote:

    On Thu, 2008-08-21 at 23:18 +0100, Emmanuele Bassi wrote:
    > On Thu, 2008-08-21 at 14:27 -0400, Yu Feng wrote:
    > > Dear all,
    > >
    > > I made a patch that allows embedding c code snippet in vala
    > >
    > >
    > >
    > > This is quite primitive and more has to be done, especially to
    > > the vala variable names to cnames.
    > no, please: let's not turn Vala into the new GOB. this makes the
    code an
    > unbearable mess - been there, done that.
    I don't agree with you.

    It is whom that messed up GOB messed up GOB.

    The code snippet is quite different from how embedding c code is
    done in
    GOB. Please have a look at the example given in the bug report.

    The embedded code is in unit of member methods. It is something
    to Watcom's embedding asm in their C compiler. You define a function,
    and the function has an assembly body.

    People can always write messy code if they like. It doesn't depend on
    the language features.

    I personally consider the c code embedding more like an
    alternative way
    to glue C code with vala than the vast number of quirks in .vapi

    The following example may help you appreciate the snoippet patch:

    using GLib;
    class mystring {
       [CCode (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);
    class ClassA: Object {
       public static void main(string [] args) {
           ClassA obj = new ClassA();
           string test = "hello world\n line 2\n line3\n";
           string [] lines = ((mystring)test).mysplit("\n", -1);
           foreach(string s in lines) {
               message("%s", s);

    mystring.mysplit is an analogue with GLib.string.split, but it returns
    the string length as well.

    I am working on a further patch to compile the wrapped (with VVV ^^^)
    code even if it is in a .vapi file.

    At least this snippet thing can help us move some of knowledge of GLib
    away from valac to the .vapi bindings. (hopefully also the reference
    counting hell of GList, GSlist, and even vala array).

    There is also a hope to solve as mentioned by


Did you know that vala supports the "extern" modifier ?

extern void foo (int f);

and then create a .c file and define
void foo (int f) {g_debug ("Hello world %d", f);}

and then compile and link everything.

Not bad, but what about redistribute bindings with "extern" files?

At this moment binding is only plain text vapi file. I can copy this file to project or system wide and use it. It's simple.

But how I can use system wide bindings (such glib-2.0.vapi) with extern C files?

Vala-list mailing list
Vala-list gnome org

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