I am fairly new to D and try to implement a python wrapper for my first code using the pyd framework. I follow the example code provided at http://svn.dsource.org/projects/pyd/trunk/raw_html/class_wrapping.html but the recipe for wrap_class seems to fail. My code snippet
import pyd.pyd;
import pyd.class_wrap;
class Foo {
int m_i;
this() { m_i = 0; }
this(int j) { m_i = j; }
this(int j, int k) { m_i = j + k; }
int i() { return m_i; }
void i(int j) { m_i = j; }
void foo(char[] s) {
import std.stdio;
writefln(s, m_i);
}
Foo opAdd(Foo rhs) {
return new Foo(m_i + rhs.m_i);
}
}
extern(C) void PydMain() {
module_init();
// Call wrap_class
wrap_class!(
Foo,
// Wrap the "foo" method
Def!(Foo.foo),
// Wrap the "i" property
Property!(Foo.i),
// Wrap the constructors.
Init!(void function(int), void function(int, int))
);
}
which is essentially copied form the example fails to compute with the following error:
/usr/local/lib/python2.7/dist-packages/pyd/infrastructure/pyd/class_wrap.d(526): Error: tuple index 0 exceeds 0
/usr/local/lib/python2.7/dist-packages/pyd/infrastructure/pyd/class_wrap.d(534): Error: template instance pyd.class_wrap.Init!(void function(int), void function(int, int)).Init.Inner!(Foo) error instantiating
/usr/local/lib/python2.7/dist-packages/pyd/infrastructure/pyd/make_wrapper.d(126): instantiated from here: shim!(2LU, Foo)
/usr/local/lib/python2.7/dist-packages/pyd/infrastructure/pyd/make_wrapper.d(136): 4 recursive instantiations from here: class_decls!(0u, Foo, Def!(foo), Property!(i), Init!(void function(int), void function(int, int)))
/usr/local/lib/python2.7/dist-packages/pyd/infrastructure/pyd/class_wrap.d(1483): instantiated from here: make_wrapper!(Foo, Def!(foo), Property!(i), Init!(void function(int), void function(int, int)))
/usr/local/lib/python2.7/dist-packages/pyd/infrastructure/pyd/class_wrap.d(1476): instantiated from here: _wrap_class!(Foo, "Foo", "", "", Def!(foo), Property!(i), Init!(void function(int), void function(int, int)))
pystochcalc.d(35): instantiated from here: wrap_class!(Foo, Def!(foo), Property!(i), Init!(void function(int), void function(int, int)))
error: command 'dmd' failed with exit status 1
Does anyone have an idea what this error message tells me and how I can fix it? Thanks!
pyd at dsource is outdated. Use pyd from GitHub - https://github.com/ariovistus/pyd . For examples check the /examples folder. Check the /examples/wrap for an example which shows how to do these sorts of things.