1 module inherit;
2 
3 import pyd.pyd;
4 import std.stdio;
5 
6 class Base {
7     this(int i) { writefln("Base.this(): ", i); }
8     void foo() {
9         writefln("Base.foo");
10     }
11     void bar() {
12         writefln("Base.bar");
13     }
14 }
15 
16 class Derived : Base {
17     this(int i) { super(i); writefln("Derived.this(): ", i); }
18     override void foo() {
19         writefln("Derived.foo");
20     }
21 }
22 
23 void call_poly(Base b) {
24     writefln("call_poly:");
25     b.foo();
26 }
27 
28 Base b1, b2, b3;
29 
30 Base return_poly_base() {
31     if (b1 is null) b1 = new Base(1);
32     return b1;
33 }
34 
35 Base return_poly_derived() {
36     if (b2 is null) b2 = new Derived(2);
37     return b2;
38 }
39 
40 extern(C) void PydMain() {
41     def!(call_poly)();
42     def!(return_poly_base)();
43     def!(return_poly_derived)();
44 
45     module_init();
46 
47     wrap_class!(
48         Base,
49         Init!(int),
50         Def!(Base.foo),
51         Def!(Base.bar)
52     )();
53 
54     wrap_class!(
55         Derived,
56         Init!(int),
57         Def!(Derived.foo)
58     )();
59 }
60