www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Pyd: Using the new mixins

reply Kirk McDonald <kirklin.mcdonald gmail.com> writes:
Revision 100 of Pyd uses the new mixins to automatically generate "shim" 
classes, one of which must be made for every class which is exposed to 
Python. (Revision 100 should be considered semi-broken, since I got all 
the big stuff done, but a few details need to be gone over. Also, it 
requires DMD 1.005, which GDC is not yet up to par with, so Linux 
support is currently broken.)

There's little to show for this. The major effect of revision 100 is a 
vast /reduction/ in code. Wrapping a class is now as simple as:

class Foo {
     void bar() {
         writefln("Foo.bar");
     }
}

extern(C) void PydMain() {
     module_init();
     wrap_class!(
         Foo,
         Def!(Foo.bar)
     );
}

This now properly handles all polymorphic behavior between D and Python:

// A D function
void polymorphic_call(Foo f) {
     f.bar();
}

# A Python subclass
class PyFoo(Foo):
     def bar(self):
         print "PyFoo.bar"

 # And in Python's interactive mode
 p = PyFoo()
 polymorphic_call(p)



And /that/ is quite something. -- Kirk McDonald http://kirkmcdonald.blogspot.com Pyd: Connecting D and Python http://pyd.dsource.org
Feb 17 2007
parent reply Walter Bright <newshound digitalmars.com> writes:
Kirk McDonald wrote:
 The major effect of revision 100 is a 
 vast /reduction/ in code.

This is such great news. It shows we are going in the right direction.
Feb 17 2007
parent Kirk McDonald <kirklin.mcdonald gmail.com> writes:
Walter Bright wrote:
 Kirk McDonald wrote:
 The major effect of revision 100 is a vast /reduction/ in code.

This is such great news. It shows we are going in the right direction.

Note that this only means a reduction in the amount of code needed to /use/ Pyd. Pyd itself is slightly larger and more complicated. :-) -- Kirk McDonald http://kirkmcdonald.blogspot.com Pyd: Connecting D and Python http://pyd.dsource.org
Feb 17 2007