Thread overview | |||||
---|---|---|---|---|---|
|
February 17, 2007 Pyd: Using the new mixins | ||||
---|---|---|---|---|
| ||||
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)
PyFoo.bar
And /that/ is quite something.
--
Kirk McDonald
http://kirkmcdonald.blogspot.com
Pyd: Connecting D and Python
http://pyd.dsource.org
|
February 17, 2007 Re: Pyd: Using the new mixins | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kirk McDonald | 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.
|
February 17, 2007 Re: Pyd: Using the new mixins | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | 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 |
Copyright © 1999-2021 by the D Language Foundation