calling D2 routines from C routines on linux
Charles Hixson
charleshixsn at earthlink.net
Tue Jul 19 17:31:13 PDT 2011
I notice I've skipped the main reason.
What I'd like to do is build libraries in D that I can call from
multiple languages. C, Python, C++, Ada, Fortran, Lisp, whatever. Just
about every language has a C interface. So if I can call the library
from C, then I can call it from anywhere. (Possibly except D. Not sure
about that, but I think the runtime functions might clash.)
On 07/19/2011 04:48 PM, Andrej Mitrovic wrote:
> See if this works for you:
>
> import core.runtime;
>
> void myMainFunc()
> {
> }
>
> extern (C)
> int initializeDee()
> {
> int result;
> void exceptionHandler(Throwable e) { throw e; }
>
> try
> {
> Runtime.initialize(&exceptionHandler);
> result = myMainFunc();
> Runtime.terminate(&exceptionHandler);
> }
> catch (Throwable o)
> {
> result = 0;
> }
> return result;
> }
>
> This is similar to how it's done for Windows GUI applications, where
> we have to manually run the initialize function in druntime (unless
> it's hidden by some GUI framework).
More information about the Digitalmars-d-learn
mailing list