Skip to content

Commit

Permalink
* Class wrapping API replaced.
Browse files Browse the repository at this point in the history
* 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.

git-svn-id: http://svn.dsource.org/projects/pyd/trunk@100 1df65b71-e716-0410-9316-ac55df2b1602
  • Loading branch information
KirkMcDonald authored and KirkMcDonald committed Feb 17, 2007
1 parent a55e8de commit 966c938
Show file tree
Hide file tree
Showing 19 changed files with 412 additions and 242 deletions.
59 changes: 12 additions & 47 deletions examples/inherit/inherit.d
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,6 @@ class Derived : Base {
}
}

class BaseWrap : Base {
mixin OverloadShim;
this(int i) { super(i); }
void foo() {
get_overload(&super.foo, "foo");
}
void bar() {
get_overload(&super.bar, "bar");
}
}

class DeriveWrap : Derived {
mixin OverloadShim;
this(int i) { super(i); }
void foo() {
get_overload(&super.foo, "foo");
}
}

void call_poly(Base b) {
writefln("call_poly:");
b.foo();
Expand All @@ -56,40 +37,24 @@ Base return_poly_derived() {
return b2;
}

Base return_poly_wrap() {
if (b3 is null) b3 = new DeriveWrap(3);
return b3;
}

extern(C) void PydMain() {
def!(call_poly);
def!(return_poly_base);
def!(return_poly_derived);
def!(return_poly_wrap);

module_init();

wrapped_class!(Base) b;
b.hide();
b.def!(Base.foo);
b.def!(Base.bar);
finalize_class(b);

wrapped_class!(Derived) d;
d.hide();
d.def!(Derived.foo);
finalize_class(d);

wrapped_class!(BaseWrap, "Base") bw;
bw.init!(void function(int));
bw.def!(BaseWrap.foo);
bw.def!(BaseWrap.bar);
finalize_class(bw);

wrapped_class!(DeriveWrap, "Derived") dw;
dw.init!(void function(int));
dw.parent!(BaseWrap);
dw.def!(DeriveWrap.foo);
finalize_class(dw);
wrap_class!(
Base,
Init!(void function(int)),
Def!(Base.foo),
Def!(Base.bar)
);

wrap_class!(
Derived,
Init!(void function(int)),
Def!(Derived.foo)
);
}

3 changes: 0 additions & 3 deletions examples/inherit/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ def foo(self):
#assert type(b2) == inherit.Derived
print "inherit.return_poly_derived returned the same object twice"
assert b2 is b2a
b3 = inherit.return_poly_wrap()
print "inherit.return_poly_wrap returned instance of DeriveWrap"
assert type(b3) == inherit.Derived

print
print '-------'
Expand Down
7 changes: 7 additions & 0 deletions examples/testdll/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,15 @@ def foo():

print

print "Testing class wrapping"
a = testdll.Foo(10)
print "Class instantiated!"
print "Testing method wrapping:"
a.foo()
print "Testing property wrapping:"
print a.i
a.i = 50
print a.i

print "Testing opApply wrapping:"
try:
Expand Down
29 changes: 13 additions & 16 deletions examples/testdll/testdll.d
Original file line number Diff line number Diff line change
Expand Up @@ -117,21 +117,18 @@ extern(C) void PydMain() {

module_init();

wrapped_class!(Foo) f;
// Constructor wrapping
f.init!(void function(int), void function(int, int));
// Member function wrapping
f.def!(Foo.foo);
// Property wrapping
f.prop!(Foo.i);
finalize_class(f);

wrapped_struct!(S) s;
s.def!(S.write_s);
const size_t i = S.i.offsetof;
const size_t t = S.s.offsetof;
s.member!(int, i, "i");
s.member!(char[], t, "s");
finalize_struct(s);
wrap_class!(
Foo,
Init!(void delegate(int), void delegate(int, int)),
Property!(Foo.i),
Def!(Foo.foo)
);

wrap_struct!(
S,
Def!(S.write_s),
Member!("i"),
Member!("s")
);
}

2 changes: 1 addition & 1 deletion infrastructure/pyd/LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2006 Kirk McDonald
Copyright 2006, 2007 Kirk McDonald

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
Loading

0 comments on commit 966c938

Please sign in to comment.