Pyd

Kirk McDonald kirklin.mcdonald at gmail.com
Fri Jun 30 22:57:20 PDT 2006


Kirk McDonald wrote:
> Important things left to do:
> * Add the wrapped types to the conversion templates. This is fairly 
> trivial, actually.
> 

Done! This greatly expands the usefulness of Pyd:

[testdll.d]
module testdll;

import pyd.pyd;
import std.stdio;

class Foo {
     int m_i;
     this() { }
     this(int i) { m_i = i; }
     this(int i, int j) { m_i = i + j; }
     void foo() {
         writefln("Foo.foo(): i = %s", m_i);
     }
     int i() { return m_i; }
}

Foo spam(Foo f) {
     f.foo();
     Foo g = new Foo(f.i + 10);
     return g;
}

extern (C)
export void inittestdll() {
     def!("spam", spam);

     module_init("testdll");

     auto Foo_ = wrap_class!("Foo", Foo)();
     Foo_.init!(ctor!(int), ctor!(int, int));
     Foo_.def!("foo", Foo.foo);
     Foo_.def!("i", Foo.i);
     finalize_class(Foo_);
}

And in Python:

 >>> import testdll
 >>> a = testdll.Foo(10)
 >>> b = testdll.spam(a)
Foo.foo(): i = 10
 >>> b.i()
20

:-)

-- 
Kirk McDonald
Pyd: Wrapping Python with D
http://dsource.org/projects/pyd/wiki



More information about the Digitalmars-d mailing list