www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Writing .di files

reply "Minas" <minas_mina1990 hotmail.co.uk> writes:
Is there a good tutorial about how to write .di files?
Jun 17 2012
next sibling parent David <d dav1d.de> writes:
Am 17.06.2012 16:04, schrieb Minas:
 Is there a good tutorial about how to write .di files?

You don't write them, the compiler outputs them with the -H option.
Jun 17 2012
prev sibling next sibling parent Jordi Sayol <g.sayol yahoo.es> writes:
Al 17/06/12 16:04, En/na Minas ha escrit:
 Is there a good tutorial about how to write .di files?
 

http://dlang.org/dmd-linux.html#interface_files -- Jordi Sayol
Jun 17 2012
prev sibling next sibling parent "Minas Mina" <minas_mina1990 hotmail.co.uk> writes:
I'm sorry, what I meant was "how to interface to C code". Sorry 
for writing it in a bad way.

Do I just declare the C code as extern and then link together 
with the C .lib/.o/.so file? (I'm in Ubuntu)

What about the stuff that is in header files?
Jun 22 2012
prev sibling parent 1100110 <10equals2 gmail.com> writes:
On Fri, 22 Jun 2012 13:13:52 -0500, Minas Mina  
<minas_mina1990 hotmail.co.uk> wrote:

 I'm sorry, what I meant was "how to interface to C code". Sorry for  
 writing it in a bad way.

 Do I just declare the C code as extern and then link together with the C  
 .lib/.o/.so file? (I'm in Ubuntu)

 What about the stuff that is in header files?

Take a look at the Deimos Repos on Github. https://github.com/D-Programming-Deimos Take a look at ncurses there. There are two folders, C and deimos. It needs to be cleaned up, but you'll notice that the .d files are really nothing more than a direct translation of the C header files. Include the translated header and link with the C library. If you have a specific library that you want to interface to, it's pretty easy once you realize what needs to be done. Global variables in C are truly global, but in D they are Thread Local. So certain variables will need to be immutable, shared, __gshared, whatever. Everything will need to be wrapped with 'extern (C)' The biggest issues your likely to face are the Thread Local Storage issues and the preprocessor directives. dmd -vtls will print out the problem vars... You can translate partial header files, just make sure you get all the relevant bits. If you wanna play around, then add this to a file and compile it. import std.string: toStringz; extern (C) int system(in char* command); auto newTerm(S:string)(S command) { return system(command.toStringz); } Yeah, I hate dealing with toStringz directly.... Unlike the functions in std.process, this one will allow interactive programs to be run from inside a D file. try newTerm("vim ~/.vimrc"); Yeah i just killed my terminal making sure std.process wouldn't work with that. -- Using Opera's revolutionary email client: http://www.opera.com/mail/
Jun 22 2012