From f6095119fe95ae83c8bd2385537e30519105bd61 Mon Sep 17 00:00:00 2001 From: KirkMcDonald Date: Mon, 14 Aug 2006 20:33:21 +0000 Subject: [PATCH] html_doc: Automatic operator overloading documented git-svn-id: http://svn.dsource.org/projects/pyd/trunk@36 1df65b71-e716-0410-9316-ac55df2b1602 --- html_doc/class_wrapping.html | 32 +++++++++++++++++++++++++++----- html_doc/pyd.css | 14 ++++++++++++++ 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/html_doc/class_wrapping.html b/html_doc/class_wrapping.html index 3796ef3..c106d90 100644 --- a/html_doc/class_wrapping.html +++ b/html_doc/class_wrapping.html @@ -62,11 +62,22 @@

Class wrapping

If you have a class Foo, you can check whether it is wrapped by simply checking whether is_wrapped!(Foo) is true. It is important to note that this is not a const bool, it is a runtime check.

-

Automatic operator overloading

+

Automatic operator overloading

-

Docs coming soon...

+

Pyd will automatically wrap most of D's operator overload functions with appropriate Python operator overloads. There are some caveats:

-

Examples

+ + +

At the moment, only the following operator overloads are supported:

+ +

opAdd, opSub, opMul, opDiv, opMod, opAnd, opOr, opXor, opShl, opShr, opCat, opAddAssign, opSubAssign, opMulAssign, opDivAssign, opModAssign, opAndAssign, opOrAssign, opXorAssign, opShlAssign, opShrAssign, opCatAssign, opIn_r

+ +

Most notably missing from this list are opIndex, opIndexAssign, opSlice, opSliceAssign, opCall, and opApply. Support for these operators is forthcoming. Also missing from the list are opUShr and opUShrAssign. Python does not have an unsigned right-shift operator, so these operator overloads are not supported. (You may still wrap them with a normal method using wrapped_class.def, of course.)

+ +

Examples

Suppose we have the following simple class:

@@ -77,6 +88,7 @@

Examples

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; } @@ -84,6 +96,10 @@

Examples

void foo(char[] s) { writefln(s, m_i); } + + Foo opAdd(Foo rhs) { + return new Foo(m_i + rhs.m_i); + } }

We would expose this class to Python by putting this code in our init function after the call to module_init:

@@ -94,8 +110,8 @@

Examples

f.def!(Foo.foo, "foo"); // Wrap the "i" property f.prop!(Foo.i, "i"); -// Wrap the constructor. -f.init!(tuple!(int)); +// Wrap the constructors. +f.init!(tuple!(int), tuple!(int, int)); finalize_class(f);

Now we can use this type from within Python like any other type.

@@ -107,9 +123,15 @@

Examples

>>> f.i = 20 >>> f.foo("Hello! i is ") Hello! i is 20 +>>> f = Foo(10, 10) +>>> f.i +20 >>> g = Foo(30) >>> g.i 30 +>>> e = f + g +>>> e.i +50 >>> # We can even subclass our D type >>> class MyFoo(Foo): ... def bar(self): diff --git a/html_doc/pyd.css b/html_doc/pyd.css index 401db95..3c9d7f7 100644 --- a/html_doc/pyd.css +++ b/html_doc/pyd.css @@ -25,6 +25,7 @@ div#nav { line-height: 140%; width: 150px; } +/* navbar links */ a.nav { text-decoration: none; font-weight: bold; @@ -40,6 +41,7 @@ a.nav:hover { color: black; background-color: #d8d8d8; } +/* the current navbar link */ a.navcur { text-decoration: none; font-weight: bold; @@ -56,6 +58,18 @@ a.navcur:hover { color: #f0f0f0; background-color: #305880; } +/* section header anchors */ +a.anchor { + color: black; +} +a.anchor:active { + color: black; +} +a.anchor:hover { + text-decoration: none; + background-color: #d8d8d8; +} +/* normal links */ a { color: #103860; }