From 77580e22b7bedfc71b01233e5c349f9c65801977 Mon Sep 17 00:00:00 2001 From: KirkMcDonald Date: Sat, 24 Jun 2006 03:58:50 +0000 Subject: [PATCH] git-svn-id: http://svn.dsource.org/projects/pyd/trunk@11 1df65b71-e716-0410-9316-ac55df2b1602 --- build_wiki_ddoc.bat | 3 + pyd/wiki_doc/def.html | 42 ++ pyd/wiki_doc/exception.html | 25 ++ pyd/wiki_doc/ftype.html | 48 +++ pyd/wiki_doc/lazy_load.html | 17 + pyd/wiki_doc/make_object.html | 85 +++++ pyd/wiki_doc/object.html | 589 +++++++++++++++++++++++++++++ pyd/wiki_doc/pyd.html | 9 + pyd/wiki_doc/wiki_doc/wikidoc.ddoc | 2 + 9 files changed, 820 insertions(+) create mode 100644 build_wiki_ddoc.bat create mode 100644 pyd/wiki_doc/def.html create mode 100644 pyd/wiki_doc/exception.html create mode 100644 pyd/wiki_doc/ftype.html create mode 100644 pyd/wiki_doc/lazy_load.html create mode 100644 pyd/wiki_doc/make_object.html create mode 100644 pyd/wiki_doc/object.html create mode 100644 pyd/wiki_doc/pyd.html create mode 100644 pyd/wiki_doc/wiki_doc/wikidoc.ddoc diff --git a/build_wiki_ddoc.bat b/build_wiki_ddoc.bat new file mode 100644 index 0000000..8d400c9 --- /dev/null +++ b/build_wiki_ddoc.bat @@ -0,0 +1,3 @@ +C:\dmd\dmd\bin\dmd.exe -o- -Ddpyd\wiki_doc pyd\def.d pyd\exception.d pyd\ftype.d pyd\lazy_load.d pyd\make_object.d pyd\object.d pyd\pyd.d pyd\wiki_doc\wiki_doc\wikidoc.ddoc + +pause diff --git a/pyd/wiki_doc/def.html b/pyd/wiki_doc/def.html new file mode 100644 index 0000000..a45adc3 --- /dev/null +++ b/pyd/wiki_doc/def.html @@ -0,0 +1,42 @@ +

pyd.def

+ +

+
template def(char[] name,alias fn)
+
Wraps a D function, making it callable from Python. +

+For example: +
import pyd.pyd;
+char[] foo(int i) {
+    if (i > 10) {
+        return "It's greater than 10!";
+    } else {
+        return "It's less than 10!";
+    }
+}
+extern (C)
+export void inittestdll() {
+    def!("foo", foo);
+    module_init("testdll");
+}
+

+ + And in Python: +

+ +
>>> import testdll
+>>> print testdll.foo(20)
+It's greater than 10!
+ +

+ +
+
+
void module_init(char[] name); +
+
Module initialization function. Should be called after the last call to def. + +

+ +
+
+ diff --git a/pyd/wiki_doc/exception.html b/pyd/wiki_doc/exception.html new file mode 100644 index 0000000..f4fde84 --- /dev/null +++ b/pyd/wiki_doc/exception.html @@ -0,0 +1,25 @@ +

pyd.exception

+ +

+
void handle_exception(); +
+
This function first checks if a Python exception is set, and then (if one + is) pulls it out, stuffs it in a PythonException, and throws that exception. +

+If this exception is never caught, it will be handled by the function + wrapping template and passed right back into Python as though nothing + happened. + +

+ +
+
class PythonException: object.Exception; +
+
This simple exception class holds a Python exception. + +

+ +
+
+
+ diff --git a/pyd/wiki_doc/ftype.html b/pyd/wiki_doc/ftype.html new file mode 100644 index 0000000..022d48a --- /dev/null +++ b/pyd/wiki_doc/ftype.html @@ -0,0 +1,48 @@ +

pyd.ftype

+ +This module contains templates for inferring the number of arguments, + the return type, and argument types of an arbitrary function pointer. +

+Portions of this module were automatically generated by Python modules. + +

+Authors:
+Daniel Keep, Tomasz Stachowiak +

+Date:
+Fri Jun 23 20:44:59 2006 + + +

+ +
template NumberOfArgs(Tf)
+
Derives the number of arguments the passed function type accepts. It only + works on functions with 10 or fewer arguments. + +

+ +
+
+
template ReturnType(T)
+
Derives the return type of the passed function type. + +

+ +
+
+
template ArgType(Tf,uint n)
+
Derives the type of an individual argument of function Tf. +

+Params:
+ + + + +
TfA function pointer type
nThe 1-indexed function argument to get the type of, e.g.: +
int func(int, char, real);
+static assert( is(char == ArgType(&func, 2)) );

+ +
+
+
+ diff --git a/pyd/wiki_doc/lazy_load.html b/pyd/wiki_doc/lazy_load.html new file mode 100644 index 0000000..39e47f0 --- /dev/null +++ b/pyd/wiki_doc/lazy_load.html @@ -0,0 +1,17 @@ +

pyd.lazy_load

+ +

+
template lazy_load(alias D,alias P)
+
This nifty template will lazily-load singleton objects, only actually + allocating them the first time they are used. This can be signifigant in a + small application, where few or even none of the many singletons in this + API are needed. +

+This is used internally, and is probably not very useful to the end user. + +

+ +
+
+
+ diff --git a/pyd/wiki_doc/make_object.html b/pyd/wiki_doc/make_object.html new file mode 100644 index 0000000..c94702e --- /dev/null +++ b/pyd/wiki_doc/make_object.html @@ -0,0 +1,85 @@ +

pyd.make_object

+ +This module contains some useful type conversion functions. There are two + interesting operations involved here: +

+PyObject* -> D type +

+ + D type -> PyObject* +

+ + The former is handled by d_type, the latter by _py. The py function is + provided as a convenience to directly convert a D type into an instance of + DPyObject. + +

+ +
template _py(T)
+


+
PyObject* _py(T t); +
+
Returns a new (owned) reference to a Python object based on the passed + argument. If the passed argument is a PyObject*, this "steals" the + reference. (In other words, it returns the PyObject* without changing its + reference count.) If the passed argument is a DPyObject, this returns a new + reference to whatever the DPyObject holds a reference to. +

+If the passed argument can't be converted to a PyObject, a Python + RuntimeError will be raised and this function will return null. + +

+ +
+
+
+
template py(T)
+


+
DPyObject py(T t); +
+
Constructs an object based on the type of the argument passed in. +

+For example, calling py(10) would return a DPyObject holding the value 10. +

+ + Calling this with a DPyObject will return back a reference to the very same + DPyObject. +

+ + Calling this with a PyObject* will "steal" the reference. + +

+ +
+
+
+
class DPyConversionException: object.Exception; +
+
An exception class used by d_type. + +

+ +
+
+
template d_type(T)
+


+
T d_type(PyObject* o); +
+
This converts a PyObject* to a D type. The template argument is the type to + convert to. The function argument is the PyObject* to convert. For instance: +

+
PyObject* i = PyInt_FromLong(20);
+int n = d_type!(int)(i);
+assert(n == 20);
+

+ + This throws a DPyConversionException if the PyObject can't be converted to + the given D type. + +

+ +
+
+
+
+ diff --git a/pyd/wiki_doc/object.html b/pyd/wiki_doc/object.html new file mode 100644 index 0000000..0fe258d --- /dev/null +++ b/pyd/wiki_doc/object.html @@ -0,0 +1,589 @@ +

pyd.object

+ +

+
class DPyObject; +
+
Wrapper class for a Python/C API PyObject. +

+Nearly all of these member functions may throw a PythonException if the + underlying Python API raises a Python exception. + +

+Authors:
+Kirk McDonald +

+Date:
+June 18, 2006 +

+See Also:
+The Python/C API + +

+ +
this(PyObject * o, bool borrowed = false); +
+
Wrap around a passed PyObject*. +

+Params:
+ + + + +
PyObject * oThe PyObject to wrap.
bool borrowedWhether o is a borrowed reference. Instances + of DPyObject always own their references. + Therefore, Py_INCREF will be called if borrowed is + true.

+ +
+
this(); +
+
The default constructor constructs an instance of the Py_None DPyObject. +

+ +
+
PyObject * ptr(); +
+
Returns a borrowed reference to the PyObject. + +

+ +
+
bool hasattr(char[] attr_name); +
+
Same as hasattr(this, attr_name) in Python. +

+ +
+
bool hasattr(DPyObject attr_name); +
+
Same as hasattr(this, attr_name) in Python. +

+ +
+
DPyObject getattr(char[] attr_name); +
+
Same as getattr(this, attr_name) in Python. +

+ +
+
DPyObject getattr(DPyObject attr_name); +
+
Same as getattr(this, attr_name) in Python. +

+ +
+
void setattr(char[] attr_name, DPyObject v); +
+
Same as setattr(this, attr_name, v) in Python. + +

+ +
+
void setattr(DPyObject attr_name, DPyObject v); +
+
Same as setattr(this, attr_name, v) in Python. + +

+ +
+
void delattr(char[] attr_name); +
+
Same as del this.attr_name in Python. + +

+ +
+
void delattr(DPyObject attr_name); +
+
Same as del this.attr_name in Python. + +

+ +
+
int opCmp(DPyObject rhs); +
+
Exposes Python object comparison to D. Same as cmp(this, rhs) in Python. + +

+ +
+
bool opEquals(DPyObject rhs); +
+
Exposes Python object equality check to D. + +

+ +
+
DPyObject repr(); +
+
Same as repr(this) in Python. +

+ +
+
DPyObject str(); +
+
Same as str(this) in Python. +

+ +
+
char[] toString(); +
+
Allows use of DPyObject in writef via %s +

+ +
+
DPyObject unicode(); +
+
Same as unicode(this) in Python. +

+ +
+
bool isInstance(DPyObject cls); +
+
Same as isinstance(this, cls) in Python. +

+ +
+
bool isSubclass(DPyObject cls); +
+
Same as issubclass(this, cls) in Python. Only works if this is a class. +

+ +
+
bool callable(); +
+
Same as callable(this) in Python. +

+ +
+
DPyObject opCall(DPyObject args = cast(DPyObject)null); +
+
Calls the DPyObject. +

+Params:
+ + +
DPyObject argsShould be a DPyTuple of the arguments to pass. Omit to + call with no arguments.

+Returns:
+Whatever the function DPyObject returns. + +

+ +
+
DPyObject opCall(DPyObject args, DPyObject kw); +
+
Calls the DPyObject with positional and keyword arguments. +

+Params:
+ + + + +
DPyObject argsPositional arguments. Should be a DPyTuple. Pass an empty + DPyTuple for no positional arguments.
DPyObject kwKeyword arguments. Should be a DPyDict.

+Returns:
+Whatever the function DPyObject returns. + +

+ +
+
DPyObject method(char[] name, DPyObject args = cast(DPyObject)null); +
+


+
+
int hash(); +
+
Same as hash(this) in Python. +

+ +
+
bool toBool(); +
+
Same as "not not this" in Python. +

+ +
+
bool not(); +
+
Same as "not this" in Python. +

+ +
+
DPyObject type(); +
+
Gets the type of this DPyObject. Same as type(this) in Python. +

+Returns:
+The type DPyObject of this DPyObject. + +

+ +
+
int length(); +
+
The length of this DPyObject. Same as len(this) in Python. + +

+ +
+
int size(); +
+
Same as length() +

+ +
+
DPyObject dir(); +
+
Same as dir(this) in Python. +

+ +
+
DPyObject opIndex(DPyObject key); +
+
Equivalent to o[key] in Python. +

+ +
+
DPyObject opIndex(char[] key); +
+
Equivalent to o['key'] in Python; usually only makes sense for + mappings. + +

+ +
+
DPyObject opIndex(int i); +
+
Equivalent to o[i] in Python; usually only makes sense for sequences. +

+ +
+
void opIndexAssign(DPyObject value, DPyObject key); +
+
Equivalent to o[key] = value in Python. +

+ +
+
void opIndexAssign(DPyObject value, char[] key); +
+
Equivalent to o['key'] = value in Python. Usually only makes sense for + mappings. + +

+ +
+
void opIndexAssign(DPyObject value, int i); +
+
Equivalent to o[i] = value in Python. Usually only makes sense for + sequences. + +

+ +
+
void delItem(DPyObject key); +
+
Equivalent to del o[key] in Python. +

+ +
+
void delItem(char[] key); +
+
Equivalent to del o['key'] in Python. Usually only makes sense for + mappings. + +

+ +
+
void delItem(int i); +
+
Equivalent to del o[i] in Python. Usually only makes sense for + sequences. + +

+ +
+
DPyObject opSlice(int i1, int i2); +
+
Equivalent to o[i1:i2] in Python. +

+ +
+
DPyObject opSlice(); +
+
Equivalent to o[:] in Python. +

+ +
+
void opSliceAssign(DPyObject v, int i1, int i2); +
+
Equivalent to o[i1:i2] = v in Python. +

+ +
+
void opSliceAssign(DPyObject v); +
+
Equivalent to o[:] = v in Python. +

+ +
+
void delSlice(int i1, int i2); +
+
Equivalent to del o[i1:i2] in Python. +

+ +
+
void delSlice(); +
+
Equivalent to del o[:] in Python. +

+ +
+
int opApply(int delegate(inout DPyObject) dg); +
+
Iterates over the items in a collection, be they the items in a + sequence, keys in a dictionary, or some other iteration defined for the + DPyObject's type. + +

+ +
+
int opApply(int delegate(inout DPyObject, inout DPyObject) dg); +
+
Iterate over (key, value) pairs in a dictionary. If the DPyObject is not + a dict, this simply does nothing. (It iterates over no items.) You + should not attempt to modify the dictionary while iterating through it, + with the exception of modifying values. Adding or removing items while + iterating through it is an especially bad idea. + +

+ +
+
DPyObject opAdd(DPyObject o); +
+


+
+
DPyObject opSub(DPyObject o); +
+


+
+
DPyObject opMul(DPyObject o); +
+


+
+
DPyObject opMul(int count); +
+
Sequence repetition +

+ +
+
DPyObject opDiv(DPyObject o); +
+


+
+
DPyObject floorDiv(DPyObject o); +
+


+
+
DPyObject opMod(DPyObject o); +
+


+
+
DPyObject divmod(DPyObject o); +
+


+
+
DPyObject pow(DPyObject o1, DPyObject o2 = cast(DPyObject)null); +
+


+
+
DPyObject opPos(); +
+


+
+
DPyObject opNeg(); +
+


+
+
DPyObject abs(); +
+


+
+
DPyObject opCom(); +
+


+
+
DPyObject opShl(DPyObject o); +
+


+
+
DPyObject opShr(DPyObject o); +
+


+
+
DPyObject opAnd(DPyObject o); +
+


+
+
DPyObject opXor(DPyObject o); +
+


+
+
DPyObject opOr(DPyObject o); +
+


+
+
DPyObject opAddAssign(DPyObject o); +
+


+
+
DPyObject opSubAssign(DPyObject o); +
+


+
+
DPyObject opMulAssign(DPyObject o); +
+


+
+
DPyObject opMulAssign(int count); +
+
In-place sequence repetition +

+ +
+
DPyObject opDivAssign(DPyObject o); +
+


+
+
DPyObject floorDivAssign(DPyObject o); +
+


+
+
DPyObject opModAssign(DPyObject o); +
+


+
+
DPyObject powAssign(DPyObject o1, DPyObject o2 = cast(DPyObject)null); +
+


+
+
DPyObject opShlAssign(DPyObject o); +
+


+
+
DPyObject opShrAssign(DPyObject o); +
+


+
+
DPyObject opAndAssign(DPyObject o); +
+


+
+
DPyObject opXorAssign(DPyObject o); +
+


+
+
DPyObject opOrAssign(DPyObject o); +
+


+
+
DPyObject asInt(); +
+


+
+
DPyObject asLong(); +
+


+
+
DPyObject asFloat(); +
+


+
+
int toLong(); +
+


+
+
long toLongLong(); +
+


+
+
double toDouble(); +
+


+
+
cdouble toComplex(); +
+


+
+
DPyObject opCat(DPyObject o); +
+
Sequence concatenation +

+ +
+
DPyObject opCatAssign(DPyObject o); +
+
In-place sequence concatenation +

+ +
+
int count(DPyObject v); +
+


+
+
int index(DPyObject v); +
+


+
+
DPyObject asList(); +
+
Converts any iterable DPyObject to a list +

+ +
+
DPyObject asTuple(); +
+
Converts any iterable DPyObject to a tuple +

+ +
+
bool opIn_r(DPyObject v); +
+
Same as "v in this" in Python. +

+ +
+
bool hasKey(DPyObject key); +
+
Same as opIn_r +

+ +
+
bool opIn_r(char[] key); +
+
Same as "'v' in this" in Python. +

+ +
+
bool hasKey(char[] key); +
+
Same as opIn_r +

+ +
+
DPyObject keys(); +
+


+
+
DPyObject values(); +
+


+
+
DPyObject items(); +
+


+
+
+
+
+ diff --git a/pyd/wiki_doc/pyd.html b/pyd/wiki_doc/pyd.html new file mode 100644 index 0000000..843173a --- /dev/null +++ b/pyd/wiki_doc/pyd.html @@ -0,0 +1,9 @@ +

pyd.pyd

+ +This module simply publicly imports all of the other components of the Pyd + package, making them all available from a single point. + +

+ +
+ diff --git a/pyd/wiki_doc/wiki_doc/wikidoc.ddoc b/pyd/wiki_doc/wiki_doc/wikidoc.ddoc new file mode 100644 index 0000000..9c6125f --- /dev/null +++ b/pyd/wiki_doc/wiki_doc/wikidoc.ddoc @@ -0,0 +1,2 @@ +DDOC =

$(TITLE)

+$(BODY)