www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - strategy to reuse C/C++ headers

reply CrazyJapG-ManKiller <CrazyJapG-ManKiller_member pathlink.com> writes:
Yow, lads and lasses.

I tried to write a script program to convert C/C++ headers into D, but failed.
You know, many guys trying so. This seems another critical task for us.

Do you have any standard method to reuse C/C++ headers?

Is there a flexible and perfect lexical analyzer with extendable multi-status,
whose internal tables we can change at run-time? Can XML help us?

Yours Faithfully,
Jan 14 2005
parent =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
CrazyJapG-ManKiller wrote:

 I tried to write a script program to convert C/C++ headers into D, but failed.
 You know, many guys trying so. This seems another critical task for us.
There are a few "hints" at http://www.digitalmars.com/d/htomodule.html, as well as a note at http://www.digitalmars.com/d/dcompiler.html#general
 Bugs
 These are some of the major bugs:
[...]
     * Need to write a tool to convert C .h files into D imports.
There are a few projects, such as http://www.dsource.org/projects/h2d/ and the ones at http://svn.dsource.org/svn/projects/bindings/trunk/
 Do you have any standard method to reuse C/C++ headers?
I didn't have much luck with the h2d requirements (boost, stl) so I wrote my own little Perl hack with the most common ones... http://www.algonet.se/~afb/d/h2d.pl It's not very clever, and needs a lot of cleaning up afterwards. But I've used it to convert the entire OpenGL and SDL headers... **** D also needs a tool to convert regular modules into "import modules", such as the ones used by e.g. the Phobos runtime code (and others) Import module: object.d Implementation module: internal/object.d The import module only has stubs for linking, not the code:
 class Object
 {
     void print();
     char[] toString();
     uint toHash();
     int opCmp(Object o);
     int opEquals(Object o);
 }
Which makes it similar to a header file, in terms of usage... So that you can ship just the interface, but not the source ? Maybe this little snippet would do: perl -pe 's/\{.*?\}/;/s' --anders
Jan 15 2005