D as an extension language

Kirk McDonald kirklin.mcdonald at gmail.com
Thu Aug 31 02:14:23 PDT 2006


Bill Baxter wrote:
> This is just a random musing, but curious if anyone had any comments.
> 
> I work mostly in C++ but recently I've been doing more with farming out 
> tricky bits to Python so I can develop those parts more rapidly.  That 
> works pretty well, but for some things Python is just not fast enough. 
> But still, while prototyping at least, I'd rather use a language that's 
> easier to develop in than C++.
> 
> That's where the question comes in... How about D as an extension 
> language?  For the time being, using C++ is a fact of life for a lot of 
> people due to extensive dependence on piles of C++ legacy code.  But if 
> I'm writing a new module or new functionality, it doesn't matter how it 
> does it's thing under the hood as long as it presents a C++ interface to 
> the rest of the system.
> 
> So how hard is it to do this sort of thing?
> What tools are out there to help?
> What tools would really be ideal to have but are missing?
> 
> It seems like it should be easier than the Python<->C++ connection 
> because D understands C ABI.  But most of what I've seen is about how D 
> can call C code, not how C++ can call D code.
> 
> I think it's worth thinking about.  It is one more way that D could make 
> some inroads in a C++ entrenched world.
> 
> --bb

For what it's worth, I think that D and Python go together quite nicely. 
This is the whole point of Pyd, which hopes to do for D what 
Boost.Python does for C++. (http://pyd.dsource.org) The concept of 
prototyping with Python and dropping into D when speed is needed is a 
sort of end-goal of Pyd's.

As for calling D code from C++, you should be able to call any D 
functions that are declared extern(C). Analogous to calling C code from 
D, you'll have to provide a header for C++ to #include, then just link 
as needed. The two languages can't talk to each other directly, of 
course, so you always have to go through this C layer.

There do exist tools to streamline this process to an extent, I believe, 
but I can't say as I'm familiar with them. Sorry.

-- 
Kirk McDonald
Pyd: Wrapping Python with D
http://pyd.dsource.org



More information about the Digitalmars-d mailing list