Could Vala call C language modules more conviently?
Recently, I thinking this question, found a solution to make it done, the detail of solution as follow:
- make a cinterop tool to convert C language headers to Vala modules
this tool convert C language headers to Vala file, follow the simple rule:
- rule 1: all headers share namespace: CInterop
- rule 2: headers convert as a sub namespace of CInterop, example:
stdio.h --> CInterop.Stdio --> CInterop.Stdio.fclose(FILE *stream)
stdlib.h -> CInterop.Stdlib --> CInterop.Stdio.atoi(string str)
math.h -> CInterop.Math --> CInterop.Math.floor(double x)
- rule 3: support a object list to arrange the functions about C struct object to a class
-
Compiler support
Vala compiler follow the rule to parse CInterop namespace and members -
About implemention
I know Python language has a lib named CLang, this lib parse c headers file to AST, then travel it to generate Vala modules.
just a solution to discuss, not yet to implement.
Edited by TAO ZUHONG