D vs C++

KennyTM~ kennytm at gmail.com
Tue Dec 28 00:25:25 PST 2010


On Dec 28, 10 05:19, "Jérôme M. Berger" wrote:
> spir wrote:
>> On Sun, 26 Dec 2010 22:44:04 +0100
>> "Jérôme M. Berger"<jeberger at free.fr>  wrote:
>>
>>>> 8. direct interface to C
>>> Cython gives it too: it is as easy to write a Cython interface
>>> module as to write a D interface file for a C library.
>>
>> Hum, I do not agree at all. As I see it, D binds to C directly, Lua binds to C rather easily, Python binds to C "complicatedly". (Lua's C interface layer is far simpler than Python's, but it still cannot compare to D's direct calls in both directions. The only issue AFAIK is that types, qualifiers and conventions do not exactly match.)
>>
>
> cdef extern double fooC (int bar)
> def fooPy (bar):
>      return fooC (bar)
>
> 	I don't know how Lua binds to C, but I doubt it is any easier. Or
> you could use swig which is even easier.
>
> 		Jerome

Cython ≠ Python.

In pure Python you bind C code with the 'ctypes' module.

from ctypes import *
xso = CDLL('x.so')
xso.fooC.restype = c_double
xso.fooC.argtypes = [c_int]
...
xso.fooC(4)



More information about the Digitalmars-d mailing list