-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git-svn-id: http://svn.dsource.org/projects/pyd/trunk@56 1df65b71-e716-0410-9316-ac55df2b1602
- Loading branch information
KirkMcDonald
authored and
KirkMcDonald
committed
Dec 12, 2006
1 parent
0021192
commit bcee75c
Showing
5 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module inherit; | ||
|
||
import pyd.pyd; | ||
import std.stdio; | ||
|
||
class Base { | ||
void foo() { | ||
writefln("Base.foo"); | ||
} | ||
void bar() { | ||
writefln("Base.bar"); | ||
} | ||
} | ||
|
||
class Derived : Base { | ||
void foo() { | ||
writefln("Derived.foo"); | ||
} | ||
} | ||
|
||
void call_poly(Base b) { | ||
writef("call_poly: "); | ||
b.foo(); | ||
} | ||
|
||
extern(C) | ||
export void initinherit() { | ||
def!(call_poly); | ||
|
||
module_init("inherit"); | ||
|
||
wrapped_class!(Base) b; | ||
b.def!(Base.foo); | ||
b.def!(Base.bar); | ||
finalize_class(b); | ||
|
||
wrapped_class!(Derived) d; | ||
d.def!(Derived.foo); | ||
finalize_class(d); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
This example illustrates the basic automatic inheritance support provided by | ||
Pyd. | ||
|
||
Execute the conventional distutils command | ||
python setup.py build | ||
to build. | ||
|
||
Then execute | ||
python test.py | ||
to exercise this example extension. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from celerid.support import setup, Extension | ||
|
||
projName = 'inherit' | ||
|
||
setup( | ||
name=projName, | ||
version='0.1', | ||
ext_modules=[ | ||
Extension(projName, ['inherit.d']) | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import os.path, sys | ||
import distutils.util | ||
|
||
# Append the directory in which the binaries were placed to Python's sys.path, | ||
# then import the D DLL. | ||
libDir = os.path.join('build', 'lib.%s-%s' % ( | ||
distutils.util.get_platform(), | ||
'.'.join(str(v) for v in sys.version_info[:2]) | ||
)) | ||
sys.path.append(os.path.abspath(libDir)) | ||
|
||
import inherit | ||
|
||
b = inherit.Base() | ||
d = inherit.Derived() | ||
|
||
b.foo() | ||
b.bar() | ||
d.foo() | ||
d.bar() | ||
|
||
print "issubclass(inherit.Derived, inherit.Base)" | ||
print issubclass(inherit.Derived, inherit.Base) | ||
|
||
inherit.call_poly(b) | ||
inherit.call_poly(d) | ||
|
||
class PyClass(inherit.Derived): | ||
def foo(self): | ||
print 'PyClass.foo' | ||
|
||
p = PyClass() | ||
print "The basic inheritance support breaks down here:" | ||
inherit.call_poly(p) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters