|
Revision 100, 1.0 kB
(checked in by KirkMcDonald, 2 years ago)
|
* Class wrapping API replaced.
* Inheritance "shim" classes now automatically generated.
* Requires DMD 1.005 or newer. Breaks GDC support for the moment.
* Docs not yet updated to reflect changes.
* Copyright notices updated to 2007.
|
| Line | |
|---|
| 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 |
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!(void function(int)), |
|---|
| 50 |
Def!(Base.foo), |
|---|
| 51 |
Def!(Base.bar) |
|---|
| 52 |
); |
|---|
| 53 |
|
|---|
| 54 |
wrap_class!( |
|---|
| 55 |
Derived, |
|---|
| 56 |
Init!(void function(int)), |
|---|
| 57 |
Def!(Derived.foo) |
|---|
| 58 |
); |
|---|
| 59 |
} |
|---|