Pyd

Kirk McDonald kirklin.mcdonald at gmail.com
Wed Jun 28 15:17:30 PDT 2006


http://dsource.org/projects/pyd/wiki

As of revision 16, Pyd is now capable of the following:

[testdll.d]
module testdll;

import pyd.pyd;
import std.stdio;

// Function wrapping
char[] bar(int i) {
     if (i > 10) {
         return "It's greater than 10!";
     } else {
         return "It's less than 10!";
     }
}

// Default argument support
void baz(int i=10, char[] s="moo") {
     writefln("i = %s\ns = %s", i, s);
}

// Inroads on class wrapping
class Foo {
     void foo() {
         writefln("Foo.foo()");
     }
}

extern (C)
export void inittestdll() {
     // Wrap function
     def!("bar", bar);
     // Wrap function with default arguments
     def!("baz", baz, 0);

     module_init("testdll");

     // Wrap class
     // (It sure says "Foo" a lot... I should do something about that.)
     auto Foo_ = wrap_class!("Foo", Foo)();
     Foo_.def!("foo", Foo.foo);
     finalize_class!("Foo", Foo);
}
// EOF

In Python:

 >>> import testdll
 >>> a = Foo()
 >>> a.foo()
Foo.foo()

This class wrapping support offers little more than that at this point. 
This is mostly because there are now soooo many cool things I can do 
that I must pause and catch my breath.

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

* Support for constructors other than the default constructor. This is 
not trivial. I know how I am going to do it, but it is going to involve 
hammering out a bunch of code.

* Exposure of properties (and maybe member variables, though that is 
harder).

Nifty features I can implement:
* Automatic wrapping of overloaded operators. (If you overload opAdd, it 
will automatically do the same in Python.)

* Subclassing support. (The ability to write subclasses of your D 
classes in Python.) This is actually just a matter of being careful as I 
write the wrapping templates. If I do it right, this will simply Just Work.

-Kirk McDonald



More information about the Digitalmars-d mailing list