Calling D from C - What's the present status?
Kirk McDonald
kirklin.mcdonald at gmail.com
Sat Jan 20 13:23:40 PST 2007
Frits van Bommel wrote:
> Bill Baxter wrote:
>
>> Seems like there should be a single handy extern (C) function in
>> phobos to handle that standard startup and shutdown stuff. I've seen
>> a couple of D programs that do this manually (I think the most recent
>> was one of Kirk's PyD samples). Is there some reason that stuff can't
>> just be thrown in a single DRuntimeInit / DRuntimeClose pair of
>> functions?
>
>
> Well, for one thing, the standard wrapper also catches exceptions.
> That's kind of hard to do with a pair of functions. Other than that, I
> don't see a problem with it.
>
Each function that is directly exposed to C must ensure that exceptions
do not escape from your D code. Pyd does this with a handy function
template that translates D exceptions into Python exceptions:
http://pyd.dsource.org/except_wrapping.html
You will probably have to think of some other way to handle exceptions
escaping from D, but something like Pyd's exception_catcher is one
solution to consider.
--
Kirk McDonald
Pyd: Wrapping Python with D
http://pyd.dsource.org
More information about the Digitalmars-d-learn
mailing list