D as an extension language
Don Clugston
dac at nospam.com.au
Thu Aug 31 02:45:37 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'm doing a lot of Windows stuff in C++, calling DLLs written in D. It's
not hard. You just need to use extern(C) wrappers on the D functions,
catch all the D exceptions before returning to C++, and make sure C++
doesn't hang onto any D pointers that could be gc-ed.
Otherwise, it's exactly the same as calling a C DLL.
I have some C++ code to simplify dynamic loading of D DLLs in Windows,
if you're interested (it does the name mangling for you). Useless for
Linux, of course.
> I think it's worth thinking about. It is one more way that D could make
> some inroads in a C++ entrenched world.
Absolutely.
More information about the Digitalmars-d
mailing list