4 ms·
I describe how easy it is to call C code from Python by using D as the glue layer. AMA.
by atilaneves 7y ago
I describe how easy it is to call C code from Python by using D as the glue layer. AMA.
- cannam 7y agoSo behind the scenes is a utility that scans the #included headers, runs the C preprocessor on them, then uses Clang code to pick out the declarations, wraps them for calling from D, and redefines any C macro values as D constants? Do I understand that correctly? (The other half of the puzzle being a tool called autowrap that wraps the resulting D for consumption by Python.) I'm not sure whether I personally would ever use this, but it's a very interesting exploration of the subject.
- atilaneves 7y ago> Do I understand that correctly? Yep! > (The other half of the puzzle being a tool called autowrap that wraps the resulting D for consumption by Python.) Correct. > I'm not sure whether I personally would ever use this, but it's a very interesting exploration of the subject. Python was an example. Want to call it from C# instead? Same code. Excel? Same code.
- jcelerier 7y agocould you explain the weird fascination of the D community with Excel ? there are so many "D" things for Excel and it seems really weird as an outsider - I don't remember the last time I've seen an actual Excel in the wild and not libreoffice or openoffice
- VHRanger 7y agoSince D has a fairly small community, I imagine its a handful of resourceful users in the financial sector fixing problems they're forced to deal with
- bachmeier 7y agoThere's also the fact that the Excel userbase is massive, so it's a sensible target.
- atilaneves 7y ago> could you explain the weird fascination of the D community with Excel No, because I'm not aware of one existing. The only reason I wrote excel-d is because of business reasons. > actual Excel in the wild and not libreoffice or openoffice Where I work, and in many many other places, it's all Excel. It's actually the most used programming language in the world. Maybe it shouldn't be, but it is.
- jabwork 7y agoHave you used pythons cffi and if so how would you differentiate this from that? Does this work for all revisions of C? iirc cffi works for all of c89 and most of c99
- atilaneves 7y agoNo, but I used the equivalent in Lua. I was under the impression that no solution handled preprocessor macros, but this thread corrected me. I might do a follow-up post on this.
- klyrs 7y agoI've been using Cython since it was called Pyrex, and I'm perpetually annoyed with rewriting c/c++ headers in Cython. This seems neat. But the reason that I use Cython is that I can wrap complex data structures (including templated c++ classes) and do processing in a fuzzy boundary between Python and c/c++. The "code-free" approach here seems to forbid such a fuzzy boundary. Am I wrong?
- atilaneves 7y agoI can't really comment without an example. I don't think this approach stops you from doing anything. It can (and has) allowed Python to call into templated D code, as long as you give the particular instantiation you're interested in an alias.
- biotronic 7y agoSince Cython compiles to C++, it can use C++ templates directly, without the need for creating aliases to the specific instantiations you're gonna use. As far as I understand, you'll still have to write Cython bindings, though: https://cython.readthedocs.io/en/latest/src/userguide/wrapping_CPlusPlus.html#templates https://cython.readthedocs.io/en/latest/src/userguide/wrappi...