[Vala] [.vapi] delegate types



Consider the following three files:
a.h:
typedef struct { void (*foo)(void); } bar;

a.vapi:
[CCode (has_target=false)]
public delegate void Func();

[CCode (cheader_filename="a.h", cname="bar")]
public struct Bar { Func foo; }

a.vala:
void main() {
    Bar b = { () => {} };
    b.foo();
}

Now I try to compile it:
valac a.vala --vapidir . --pkg a -X -I.

What I get is:
/home/lomereiter/a.vala.c: In function ‘_vala_main’:
/home/lomereiter/a.vala.c:30:2: error: unknown type name ‘Func’
/home/lomereiter/a.vala.c:34:9: warning: assignment makes integer from
pointer without a cast [enabled by default]
/home/lomereiter/a.vala.c:35:9: error: called object ‘_tmp2_’ is not a function
error: cc exited with status 256
Compilation failed: 1 error(s), 0 warning(s)

That is, a.vala.c is not aware of Func type.

Currently, I solve the problem not so nicely: copy a.vapi to __a.vala,
produce __a.h with -H option, leave there only typedefs concerning the
delegates; and then after compiling a.vala to a.c, add line '#include
"__a.h"' using sed; and then finally compile a.c with gcc.

Is there a better solution? Maybe another CCode option should be
added, like "generate_typedef" or something, which value of false
would mean to expand the type everywhere (into "return-type
(*variable-name) (param-types)")?



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