| 1 |
<html><head> |
|---|
| 2 |
<META http-equiv="content-type" content="text/html; charset=utf-8"> |
|---|
| 3 |
<title>pyd.make_object</title> |
|---|
| 4 |
</head><body> |
|---|
| 5 |
<h1>pyd.make_object</h1> |
|---|
| 6 |
<!-- Generated by Ddoc from pyd\make_object.d --> |
|---|
| 7 |
This module contains some useful type conversion functions. There are two |
|---|
| 8 |
interesting operations involved here: |
|---|
| 9 |
<br><br> |
|---|
| 10 |
PyObject* -> D type |
|---|
| 11 |
<br><br> |
|---|
| 12 |
|
|---|
| 13 |
D type -> PyObject* |
|---|
| 14 |
<br><br> |
|---|
| 15 |
|
|---|
| 16 |
The former is handled by d_type, the latter by _py. The py function is |
|---|
| 17 |
provided as a convenience to directly convert a D type into an instance of |
|---|
| 18 |
DPyObject. |
|---|
| 19 |
|
|---|
| 20 |
<br><br> |
|---|
| 21 |
|
|---|
| 22 |
<dl><dt><big>template _py(T)</big></dt> |
|---|
| 23 |
<dd><br><br> |
|---|
| 24 |
<dl><dt><big>PyObject* <u>_py</u>(T <i>t</i>); |
|---|
| 25 |
</big></dt> |
|---|
| 26 |
<dd>Returns a new (owned) reference to a Python object based on the passed |
|---|
| 27 |
argument. If the passed argument is a PyObject*, this "steals" the |
|---|
| 28 |
reference. (In other words, it returns the PyObject* without changing its |
|---|
| 29 |
reference count.) If the passed argument is a DPyObject, this returns a new |
|---|
| 30 |
reference to whatever the DPyObject holds a reference to. |
|---|
| 31 |
<br><br> |
|---|
| 32 |
If the passed argument can'<i>t</i> be converted to a PyObject, a Python |
|---|
| 33 |
RuntimeError will be raised and this function will return <b>null</b>. |
|---|
| 34 |
|
|---|
| 35 |
<br><br> |
|---|
| 36 |
|
|---|
| 37 |
</dd> |
|---|
| 38 |
</dl> |
|---|
| 39 |
</dd> |
|---|
| 40 |
<dt><big>template py(T)</big></dt> |
|---|
| 41 |
<dd><br><br> |
|---|
| 42 |
<dl><dt><big>DPyObject <u>py</u>(T <i>t</i>); |
|---|
| 43 |
</big></dt> |
|---|
| 44 |
<dd>Constructs an object based on the type of the argument passed in. |
|---|
| 45 |
<br><br> |
|---|
| 46 |
For example, calling <u>py</u>(10) would return a DPyObject holding the value 10. |
|---|
| 47 |
<br><br> |
|---|
| 48 |
|
|---|
| 49 |
Calling this with a DPyObject will return back a reference to the very same |
|---|
| 50 |
DPyObject. |
|---|
| 51 |
<br><br> |
|---|
| 52 |
|
|---|
| 53 |
Calling this with a PyObject* will "steal" the reference. |
|---|
| 54 |
|
|---|
| 55 |
<br><br> |
|---|
| 56 |
|
|---|
| 57 |
</dd> |
|---|
| 58 |
</dl> |
|---|
| 59 |
</dd> |
|---|
| 60 |
<dt><big>class <u>DPyConversionException</u>: object.Exception; |
|---|
| 61 |
</big></dt> |
|---|
| 62 |
<dd>An exception class used by d_type. |
|---|
| 63 |
|
|---|
| 64 |
<br><br> |
|---|
| 65 |
|
|---|
| 66 |
<dl></dl> |
|---|
| 67 |
</dd> |
|---|
| 68 |
<dt><big>template d_type(T)</big></dt> |
|---|
| 69 |
<dd><br><br> |
|---|
| 70 |
<dl><dt><big>T <u>d_type</u>(PyObject* <i>o</i>); |
|---|
| 71 |
</big></dt> |
|---|
| 72 |
<dd>This converts a PyObject* to a D type. The template argument is the type to |
|---|
| 73 |
convert to. The function argument is the PyObject* to convert. For instance: |
|---|
| 74 |
<br><br> |
|---|
| 75 |
<pre class="d_code">PyObject* i = PyInt_FromLong(20); |
|---|
| 76 |
int n = d_type!(int)(i); |
|---|
| 77 |
assert(n == 20);</pre> |
|---|
| 78 |
<br><br> |
|---|
| 79 |
|
|---|
| 80 |
This throws a DPyConversionException if the PyObject can't be converted to |
|---|
| 81 |
the given D type. |
|---|
| 82 |
|
|---|
| 83 |
<br><br> |
|---|
| 84 |
|
|---|
| 85 |
</dd> |
|---|
| 86 |
</dl> |
|---|
| 87 |
</dd> |
|---|
| 88 |
</dl> |
|---|
| 89 |
|
|---|
| 90 |
<hr><small>Page generated by <a href="http://www.digitalmars.com/d/ddoc.html">Ddoc</a>. </small> |
|---|
| 91 |
</body></html> |
|---|