Sixtease has asked for the wisdom of the Perl Monks concerning the following question:

I've been learning how to write XSubs recently. I was thinking if it was possible to use libraries written in other languages than C. I've been playing around with D and it really picked my interest. Wouldn't it be cool to be able to write the performance-critical stuff in something like that?

Replies are listed 'Best First'.
Re: Non-C XSubs
by xdg (Monsignor) on Mar 01, 2007 at 02:43 UTC

    You might want to look at some of the Inline family of modules. E.g. Inline::C, Inline::Java, etc.

    -xdg

    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

      There is currently no Inline::D, but it doesn't mean you can't make one based on the other inline modules :).
        It looks like a rather intimidating task to build an Inline::D module but it would definitely interest me to try it. I've not looked into the guts of the other Inline:: modules but the Inline's documentation says this:

        For C (and C++), Inline uses the DynaLoader::bootstrap method to pull your external module into Perl space. Now you can call all of your external functions like Perl subroutines.

        Other languages like Python and Java, provide their own loaders.

        I must admit I have little clue about loaders like this. I gather from this that I would need a loader for D, which I have no idea whether exists or how to fetch one. :-)
Re: Non-C XSubs
by ambrus (Abbot) on Mar 01, 2007 at 09:53 UTC

    Just write little wrappers in C that call your functions.

      And how would you call a D function from a C program?
        There is some information on this on the Digital Mars website. I've never used D myself, so I don't know how well it works :)
        D is ABI compatible with C.

        cat >~/.sig </dev/interesting