Python calling D

Russel Winder russel at winder.org.uk
Tue Feb 4 08:17:14 PST 2014


On Tue, 2014-02-04 at 12:45 +0000, Artem Tarasov wrote:
> On Tuesday, 4 February 2014 at 11:33:40 UTC, Russel Winder wrote:
> > The question is how to get this run.
> 
> Pointing out obvious things, part 2: wrap it into a C function 
> and call that function when loading the Python module.

I had thought of this and rejected it as an API fail. (Possibly wrongly,
but…)

> library.d:
> ...
> extern (C) export void attach() { Runtime.initialize(); }
> 
> library/__init__.py:
> ...
> lib = ctypes.CDLL("myawesomelib.so")
> lib.attach()

This violates the principle of least surprise: you don't have to do this
with C or C++ extensions so it is an API fail for D to have to do this.

> def foo():
>      lib.foo()
> ...
> 

But it does lead to a working system :-)

-- 
Russel.
=============================================================================
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder at ekiga.net
41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel at winder.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder



More information about the Digitalmars-d-learn mailing list