www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - calling from C into D

reply Aaron Watters <arw1961 yahoo.com> writes:
Ok, next question:  If I wanted to run some D stuff under
the Apache web server in embedded mode I would have to
be able to write some C code which calls into D code.
This topic is not discussed in the docs that I can find.

Is it possible to call from C into D (to embedded D code into
a larger process written in C)?  You can't do this in java
and this is one of the reasons I always was averse to java
from the beginning.

Thanks again, -- Aaron Watters
Aug 07 2009
next sibling parent reply BCS <ao pathlink.com> writes:
Reply to Aaron,

 Ok, next question:  If I wanted to run some D stuff under
 the Apache web server in embedded mode I would have to
 be able to write some C code which calls into D code.
 This topic is not discussed in the docs that I can find.
 Is it possible to call from C into D (to embedded D code into a larger
 process written in C)?  You can't do this in java and this is one of
 the reasons I always was averse to java from the beginning.
 
 Thanks again, -- Aaron Watters
 

you need to create the header files by hand but you can call from C code to D functions that are extern(C).
Aug 07 2009
parent Chad J <chadjoan __spam.is.bad__gmail.com> writes:
BCS wrote:
 Reply to Aaron,
 
 Ok, next question:  If I wanted to run some D stuff under
 the Apache web server in embedded mode I would have to
 be able to write some C code which calls into D code.
 This topic is not discussed in the docs that I can find.
 Is it possible to call from C into D (to embedded D code into a larger
 process written in C)?  You can't do this in java and this is one of
 the reasons I always was averse to java from the beginning.

 Thanks again, -- Aaron Watters

you need to create the header files by hand but you can call from C code to D functions that are extern(C).

You may also want to initialize the D runtime. An example of that for D2 can be found here: http://www.digitalmars.com/d/2.0/windows.html or for D1: http://www.digitalmars.com/d/1.0/windows.html Even though you aren't writing a Windows application, you should probably write some kind of "extern(C) init() {...}" function that your Apache code would call and thus set up the runtime.
Aug 07 2009
prev sibling parent Jesse Phillips <jessekphillips+d gmail.com> writes:
Aaron Watters Wrote:

 Ok, next question:  If I wanted to run some D stuff under
 the Apache web server in embedded mode I would have to
 be able to write some C code which calls into D code.
 This topic is not discussed in the docs that I can find.
 
 Is it possible to call from C into D (to embedded D code into
 a larger process written in C)?  You can't do this in java
 and this is one of the reasons I always was averse to java
 from the beginning.
 
 Thanks again, -- Aaron Watters

A little hidden right now http://www.prowiki.org/wiki4d/wiki.cgi?DcalledFromC
Aug 07 2009