Changeset 49
- Timestamp:
- 12/01/06 17:15:39 (5 years ago)
- Files:
-
- trunk/dcompiler.py (modified) (2 diffs)
- trunk/html_doc/basics.html (modified) (2 diffs)
- trunk/html_doc/celerid.html (modified) (1 diff)
- trunk/html_doc/class_wrapping.html (modified) (1 diff)
- trunk/html_doc/conversion.html (modified) (5 diffs)
- trunk/html_doc/credits.html (modified) (1 diff)
- trunk/html_doc/except_wrapping.html (modified) (2 diffs)
- trunk/html_doc/func_wrapping.html (modified) (1 diff)
- trunk/html_doc/index.html (modified) (1 diff)
- trunk/html_doc/install.html (modified) (1 diff)
- trunk/html_doc/pydobject.html (moved) (moved from trunk/html_doc/dpyobject.html) (42 diffs)
- trunk/infrastructure/pyd/class_wrap.d (modified) (7 diffs)
- trunk/infrastructure/pyd/def.d (modified) (1 diff)
- trunk/infrastructure/pyd/func_wrap.d (modified) (7 diffs)
- trunk/infrastructure/pyd/iteration.d (modified) (8 diffs)
- trunk/infrastructure/pyd/make_object.d (modified) (11 diffs)
- trunk/infrastructure/pyd/pyd.d (modified) (1 diff)
- trunk/infrastructure/pyd/pydobject.d (moved) (moved from trunk/infrastructure/pyd/dpyobject.d) (43 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/dcompiler.py
r48 r49 30 30 'def.d', 31 31 'dg_convert.d', 32 'dpyobject.d',33 32 'exception.d', 34 33 'func_wrap.d', … … 37 36 'op_wrap.d', 38 37 'pyd.d', 38 'pydobject.d', 39 39 ] 40 40 trunk/html_doc/basics.html
r45 r49 18 18 <a class="nav" href="class_wrapping.html">Class wrapping</a><br /> 19 19 <a class="nav" href="except_wrapping.html">Exception wrapping</a><br /> 20 <a class="nav" href=" dpyobject.html">DPyObject</a><br />20 <a class="nav" href="pydobject.html">PydObject</a><br /> 21 21 <a class="nav" href="credits.html">Credits</a> 22 22 </div> … … 49 49 <p><code>PyObject* module_init(char[] <span class="arg">name</span>);</code></p> 50 50 51 <p>It does little more than call <a href="http://docs.python.org/api/allocating-objects.html">Py_InitModule</a> and return the new module object. This object is also available via the <code> DPy_Module_p</code> property once you've called <code>module_init</code>.</p>51 <p>It does little more than call <a href="http://docs.python.org/api/allocating-objects.html">Py_InitModule</a> and return the new module object. This object is also available via the <code>Pyd_Module_p</code> property once you've called <code>module_init</code>.</p> 52 52 53 53 <p>Due to the way in which Pyd implements function and class wrapping, any calls to <code>def</code> must occur <em>before</em> the call to <code>module_init</code>, and any calls to <code>finalize_class</code> must occur <em>after</em> the call. I know this seems like a rather arbitrary rule, but it is important. Calls to <code>def</code> in the wrong place will simply be ignored, and calls to <code>finalize_class</code> in the wrong place will throw an assert. (And this assert will cause the Python interpreter to crash. So be warned.)</p> trunk/html_doc/celerid.html
r48 r49 18 18 <a class="nav" href="class_wrapping.html">Class wrapping</a><br /> 19 19 <a class="nav" href="except_wrapping.html">Exception wrapping</a><br /> 20 <a class="nav" href=" dpyobject.html">DPyObject</a><br />20 <a class="nav" href="pydobject.html">PydObject</a><br /> 21 21 <a class="nav" href="credits.html">Credits</a> 22 22 </div> trunk/html_doc/class_wrapping.html
r45 r49 18 18 <a class="navcur" href="class_wrapping.html">Class wrapping</a><br /> 19 19 <a class="nav" href="except_wrapping.html">Exception wrapping</a><br /> 20 <a class="nav" href=" dpyobject.html">DPyObject</a><br />20 <a class="nav" href="pydobject.html">PydObject</a><br /> 21 21 <a class="nav" href="credits.html">Credits</a> 22 22 </div> trunk/html_doc/conversion.html
r45 r49 18 18 <a class="nav" href="class_wrapping.html">Class wrapping</a><br /> 19 19 <a class="nav" href="except_wrapping.html">Exception wrapping</a><br /> 20 <a class="nav" href=" dpyobject.html">DPyObject</a><br />20 <a class="nav" href="pydobject.html">PydObject</a><br /> 21 21 <a class="nav" href="credits.html">Credits</a> 22 22 </div> … … 45 45 <tr><td>delegate or function pointer</td> <td>A callable object</td></tr> 46 46 <tr><td><a href="class_wrapping.html">A wrapped class</a></td> <td>The wrapped type</td></tr> 47 <tr><td><a href=" dpyobject.html">DPyObject</a></td> <td>The wrapped object's type</td></tr>47 <tr><td><a href="pydobject.html">PydObject</a></td> <td>The wrapped object's type</td></tr> 48 48 <tr><td>PyObject*</td> <td>The object's type</td></tr> 49 49 </table> … … 51 51 This function will set a Python <code>RuntimeError</code> and return <code>null</code> if the conversion is not possible.</dd> 52 52 53 <dt><code> DPyObject py(<span class="t_arg">T</span>) (<span class="t_arg">T</span> <span class="arg">t</span>);</code></dt>54 <dd>Converts D item <span class="arg">t</span> of type <span class="t_arg">T</span> to a PyObject with the <code>_py</code> function (above), and returns a <a href=" dpyobject.html">DPyObject</a> wrapping that PyObject. This will <a href="except_wrapping.html">throw a wrapped Python <code>RuntimeError</code></a> if the conversion is not possible.</dd>53 <dt><code>PydObject py(<span class="t_arg">T</span>) (<span class="t_arg">T</span> <span class="arg">t</span>);</code></dt> 54 <dd>Converts D item <span class="arg">t</span> of type <span class="t_arg">T</span> to a PyObject with the <code>_py</code> function (above), and returns a <a href="pydobject.html">PydObject</a> wrapping that PyObject. This will <a href="except_wrapping.html">throw a wrapped Python <code>RuntimeError</code></a> if the conversion is not possible.</dd> 55 55 56 56 <dt><code><span class="t_arg">T</span> d_type(<span class="t_arg">T</span>) (PyObject* <span class="arg">o</span>);</dt> … … 60 60 <tr><th>Python type</th> <th>D type</th> </tr> 61 61 <tr><td>Any type</td> <td>PyObject*</td> </tr> 62 <tr><td>Any type</td> <td><a href=" dpyobject.html">DPyObject</a></td></tr>62 <tr><td>Any type</td> <td><a href="pydobject.html">PydObject</a></td></tr> 63 63 <tr><td><a href="class_wrapping.html">Wrapped class</a></td> <td>Wrapped class</td></tr> 64 64 <tr><td>Any callable</td> <td>delegate</td> </tr> … … 71 71 </table> 72 72 73 This function will throw a <code> DPyConversionException</code> if the conversion is not possible.</dd>73 This function will throw a <code>PydConversionException</code> if the conversion is not possible.</dd> 74 74 </dl> 75 75 </div> trunk/html_doc/credits.html
r45 r49 18 18 <a class="nav" href="class_wrapping.html">Class wrapping</a><br /> 19 19 <a class="nav" href="except_wrapping.html">Exception wrapping</a><br /> 20 <a class="nav" href=" dpyobject.html">DPyObject</a><br />20 <a class="nav" href="pydobject.html">PydObject</a><br /> 21 21 <a class="navcur" href="credits.html">Credits</a> 22 22 </div> trunk/html_doc/except_wrapping.html
r46 r49 18 18 <a class="nav" href="class_wrapping.html">Class wrapping</a><br /> 19 19 <a class="navcur" href="except_wrapping.html">Exception wrapping</a><br /> 20 <a class="nav" href=" dpyobject.html">DPyObject</a><br />20 <a class="nav" href="pydobject.html">PydObject</a><br /> 21 21 <a class="nav" href="credits.html">Credits</a> 22 22 </div> … … 30 30 <p>When wrapping functions and classes, the latter is usually of more interest. All wrapped functions, methods, constructors, properties, &c, will catch any otherwise uncaught D exceptions and translate them into a Python <code>RuntimeError</code>. <i>(In the future, I may define a new Python exception type for this purpose.)</i> This is fairly important, as any uncaught D exceptions would otherwise crash the Python interpreter.</p> 31 31 32 <p>The <a href=" dpyobject.html">DPyObject</a> class wraps a portion of the Python/C API. Whenever a Python exception is raised by a method of DPyObject, it will be thrown as a <code>PythonException</code>. This is a normal D exception that knows how to carry the complete state of a Python exception. <code>PythonException</code> objects have three properties, <code>type</code>, <code>value</code>, and <code>traceback</code>, which each return an owned reference to a <code>PyObject*</code> corresponding to a different part of a Python exception. If the <code>PythonException</code> goes uncaught, the function wrapper will catch it, and translate it back into the original Python exception.</p>32 <p>The <a href="pydobject.html">PydObject</a> class wraps a portion of the Python/C API. Whenever a Python exception is raised by a method of PydObject, it will be thrown as a <code>PythonException</code>. This is a normal D exception that knows how to carry the complete state of a Python exception. <code>PythonException</code> objects have three properties, <code>type</code>, <code>value</code>, and <code>traceback</code>, which each return an owned reference to a <code>PyObject*</code> corresponding to a different part of a Python exception. If the <code>PythonException</code> goes uncaught, the function wrapper will catch it, and translate it back into the original Python exception.</p> 33 33 34 34 <p>Pyd provides the following exception-related functions:</p> trunk/html_doc/func_wrapping.html
r45 r49 18 18 <a class="nav" href="class_wrapping.html">Class wrapping</a><br /> 19 19 <a class="nav" href="except_wrapping.html">Exception wrapping</a><br /> 20 <a class="nav" href=" dpyobject.html">DPyObject</a><br />20 <a class="nav" href="pydobject.html">PydObject</a><br /> 21 21 <a class="nav" href="credits.html">Credits</a> 22 22 </div> trunk/html_doc/index.html
r45 r49 18 18 <a class="nav" href="class_wrapping.html">Class wrapping</a><br /> 19 19 <a class="nav" href="except_wrapping.html">Exception wrapping</a><br /> 20 <a class="nav" href=" dpyobject.html">DPyObject</a><br />20 <a class="nav" href="pydobject.html">PydObject</a><br /> 21 21 <a class="nav" href="credits.html">Credits</a> 22 22 </div> trunk/html_doc/install.html
r45 r49 18 18 <a class="nav" href="class_wrapping.html">Class wrapping</a><br /> 19 19 <a class="nav" href="except_wrapping.html">Exception wrapping</a><br /> 20 <a class="nav" href=" dpyobject.html">DPyObject</a><br />20 <a class="nav" href="pydobject.html">PydObject</a><br /> 21 21 <a class="nav" href="credits.html">Credits</a> 22 22 </div> trunk/html_doc/pydobject.html
r45 r49 4 4 <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> 5 5 <link href="pyd.css" rel="stylesheet" type="text/css"> 6 <title>pyd. dpyobject</title>6 <title>pyd.pydobject</title> 7 7 </head> 8 8 … … 18 18 <a class="nav" href="class_wrapping.html">Class wrapping</a><br /> 19 19 <a class="nav" href="except_wrapping.html">Exception wrapping</a><br /> 20 <a class="navcur" href=" dpyobject.html">DPyObject</a><br />20 <a class="navcur" href="pydobject.html">PydObject</a><br /> 21 21 <a class="nav" href="credits.html">Credits</a> 22 22 </div> … … 24 24 <div id="content"> 25 25 26 <h1>pyd. dpyobject</h1>27 <!-- Generated by Ddoc from pyd\ dpyobject.d -->28 <p>The DPyObject class wraps a PyObject*, using the D garbage collector to handle the reference count so that you don't have to. It also overloads quite a lot of operators, and tries to make using Python objects in D code as much like using them in Python as possible. However, it is incomplete (the function and method call methods in particular need work, and there are a number of helper functions that need to be written), and remains a work in progress.</p>29 30 <dl><dt><big>class <u> DPyObject</u>;26 <h1>pyd.pydobject</h1> 27 <!-- Generated by Ddoc from pyd\pydobject.d --> 28 <p>The PydObject class wraps a PyObject*, using the D garbage collector to handle the reference count so that you don't have to. It also overloads quite a lot of operators, and tries to make using Python objects in D code as much like using them in Python as possible. However, it is incomplete (the function and method call methods in particular need work, and there are a number of helper functions that need to be written), and remains a work in progress.</p> 29 30 <dl><dt><big>class <u>PydObject</u>; 31 31 </big></dt> 32 32 <dd>Wrapper class for a Python/C API PyObject. … … 52 52 <tr><td>PyObject * <i>o</i></td> <td>The PyObject to wrap.</td></tr> 53 53 <tr><td>bool <i>borrowed</i></td> <td>Whether <i>o</i> is a borrowed reference. Instances 54 of DPyObject always own their references.54 of PydObject always own their references. 55 55 Therefore, Py_INCREF will be called if <i>borrowed</i> is 56 56 true.</td></tr> … … 58 58 59 59 <dt><big>this();</big></dt> 60 <dd>The default constructor constructs an instance of the Py_None DPyObject.<br /><br /></dd>60 <dd>The default constructor constructs an instance of the Py_None PydObject.<br /><br /></dd> 61 61 62 62 <dt><big>PyObject * <u>ptr</u>();</big></dt> … … 66 66 <dd>Same as hasattr(this, <i>attr_name</i>) in Python.<br><br></dd> 67 67 68 <dt><big>bool <u>hasattr</u>( DPyObject <i>attr_name</i>);68 <dt><big>bool <u>hasattr</u>(PydObject <i>attr_name</i>); 69 69 </big></dt> 70 70 <dd>Same as hasattr(this, <i>attr_name</i>) in Python. … … 72 72 73 73 </dd> 74 <dt><big> DPyObject <u>getattr</u>(char[] <i>attr_name</i>);74 <dt><big>PydObject <u>getattr</u>(char[] <i>attr_name</i>); 75 75 </big></dt> 76 76 <dd>Same as getattr(this, <i>attr_name</i>) in Python. … … 78 78 79 79 </dd> 80 <dt><big> DPyObject <u>getattr</u>(DPyObject <i>attr_name</i>);80 <dt><big>PydObject <u>getattr</u>(PydObject <i>attr_name</i>); 81 81 </big></dt> 82 82 <dd>Same as getattr(this, <i>attr_name</i>) in Python. … … 84 84 85 85 </dd> 86 <dt><big>void <u>setattr</u>(char[] <i>attr_name</i>, DPyObject <i>v</i>);86 <dt><big>void <u>setattr</u>(char[] <i>attr_name</i>, PydObject <i>v</i>); 87 87 </big></dt> 88 88 <dd>Same as setattr(this, <i>attr_name</i>, <i>v</i>) in Python. … … 91 91 92 92 </dd> 93 <dt><big>void <u>setattr</u>( DPyObject <i>attr_name</i>, DPyObject <i>v</i>);93 <dt><big>void <u>setattr</u>(PydObject <i>attr_name</i>, PydObject <i>v</i>); 94 94 </big></dt> 95 95 <dd>Same as setattr(this, <i>attr_name</i>, <i>v</i>) in Python. … … 105 105 106 106 </dd> 107 <dt><big>void <u>delattr</u>( DPyObject <i>attr_name</i>);107 <dt><big>void <u>delattr</u>(PydObject <i>attr_name</i>); 108 108 </big></dt> 109 109 <dd>Same as del this.<i>attr_name</i> in Python. … … 112 112 113 113 </dd> 114 <dt><big>int <u>opCmp</u>( DPyObject <i>rhs</i>);114 <dt><big>int <u>opCmp</u>(PydObject <i>rhs</i>); 115 115 </big></dt> 116 116 <dd>Exposes Python object comparison to D. Same as cmp(this, <i>rhs</i>) in Python. … … 119 119 120 120 </dd> 121 <dt><big>bool <u>opEquals</u>( DPyObject <i>rhs</i>);121 <dt><big>bool <u>opEquals</u>(PydObject <i>rhs</i>); 122 122 </big></dt> 123 123 <dd>Exposes Python object equality check to D. … … 126 126 127 127 </dd> 128 <dt><big> DPyObject <u>repr</u>();128 <dt><big>PydObject <u>repr</u>(); 129 129 </big></dt> 130 130 <dd>Same as repr(this) in Python. … … 132 132 133 133 </dd> 134 <dt><big> DPyObject <u>str</u>();134 <dt><big>PydObject <u>str</u>(); 135 135 </big></dt> 136 136 <dd>Same as str(this) in Python. … … 140 140 <dt><big>char[] <u>toString</u>(); 141 141 </big></dt> 142 <dd>Allows use of DPyObject in writef via %s143 <br><br> 144 145 </dd> 146 <dt><big> DPyObject <u>unicode</u>();142 <dd>Allows use of PydObject in writef via %s 143 <br><br> 144 145 </dd> 146 <dt><big>PydObject <u>unicode</u>(); 147 147 </big></dt> 148 148 <dd>Same as unicode(this) in Python. … … 150 150 151 151 </dd> 152 <dt><big>bool <u>isInstance</u>( DPyObject <i>cls</i>);152 <dt><big>bool <u>isInstance</u>(PydObject <i>cls</i>); 153 153 </big></dt> 154 154 <dd>Same as isinstance(this, <i>cls</i>) in Python. … … 156 156 157 157 </dd> 158 <dt><big>bool <u>isSubclass</u>( DPyObject <i>cls</i>);158 <dt><big>bool <u>isSubclass</u>(PydObject <i>cls</i>); 159 159 </big></dt> 160 160 <dd>Same as issubclass(this, <i>cls</i>) in Python. Only works if this is a class. … … 168 168 169 169 </dd> 170 <dt><big> DPyObject <u>opCall</u>(DPyObject <i>args</i> = null);171 </big></dt> 172 <dd>Calls the DPyObject. <strong>(Note: The opCall functions will be changing in the future to something more useful.)</strong>170 <dt><big>PydObject <u>opCall</u>(PydObject <i>args</i> = null); 171 </big></dt> 172 <dd>Calls the PydObject. <strong>(Note: The opCall functions will be changing in the future to something more useful.)</strong> 173 173 <br><br> 174 174 <b>Params:</b><br> 175 <table><tr><td> DPyObject <i>args</i></td>176 <td>Should be a DPyTuple of the arguments to pass. Omit to175 <table><tr><td>PydObject <i>args</i></td> 176 <td>Should be a PydTuple of the arguments to pass. Omit to 177 177 call with no arguments.</td></tr> 178 178 </table><br> 179 179 <b>Returns:</b><br> 180 Whatever the function DPyObject returns.181 182 <br><br> 183 184 </dd> 185 <dt><big> DPyObject <u>opCall</u>(DPyObject <i>args</i>, DPyObject <i>kw</i>);186 </big></dt> 187 <dd>Calls the DPyObject with positional and keyword arguments.180 Whatever the function PydObject returns. 181 182 <br><br> 183 184 </dd> 185 <dt><big>PydObject <u>opCall</u>(PydObject <i>args</i>, PydObject <i>kw</i>); 186 </big></dt> 187 <dd>Calls the PydObject with positional and keyword arguments. 188 188 <br><br> 189 189 <b>Params:</b><br> 190 <table><tr><td> DPyObject <i>args</i></td>191 <td>Positional arguments. Should be a DPyTuple. Pass an empty192 DPyTuple for no positional arguments.</td></tr>193 <tr><td> DPyObject <i>kw</i></td>194 <td>Keyword arguments. Should be a DPyDict.</td></tr>190 <table><tr><td>PydObject <i>args</i></td> 191 <td>Positional arguments. Should be a PydTuple. Pass an empty 192 PydTuple for no positional arguments.</td></tr> 193 <tr><td>PydObject <i>kw</i></td> 194 <td>Keyword arguments. Should be a PydDict.</td></tr> 195 195 </table><br> 196 196 <b>Returns:</b><br> 197 Whatever the function DPyObject returns.198 199 <br><br> 200 201 </dd> 202 <dt><big> DPyObject <u>method</u>(char[] <i>name</i>, DPyObject <i>args</i> = null);197 Whatever the function PydObject returns. 198 199 <br><br> 200 201 </dd> 202 <dt><big>PydObject <u>method</u>(char[] <i>name</i>, PydObject <i>args</i> = null); 203 203 </big></dt> 204 204 <dd><br><br> … … 222 222 223 223 </dd> 224 <dt><big> DPyObject <u>type</u>();225 </big></dt> 226 <dd>Gets the type of this DPyObject. Same as type(this) in Python.224 <dt><big>PydObject <u>type</u>(); 225 </big></dt> 226 <dd>Gets the type of this PydObject. Same as type(this) in Python. 227 227 <br><br> 228 228 <b>Returns:</b><br> 229 The type DPyObject of this DPyObject.229 The type PydObject of this PydObject. 230 230 231 231 <br><br> … … 234 234 <dt><big>int <u>length</u>(); 235 235 </big></dt> 236 <dd>The length of this DPyObject. Same as len(this) in Python.236 <dd>The length of this PydObject. Same as len(this) in Python. 237 237 238 238 <br><br> … … 245 245 246 246 </dd> 247 <dt><big> DPyObject <u>dir</u>();247 <dt><big>PydObject <u>dir</u>(); 248 248 </big></dt> 249 249 <dd>Same as dir(this) in Python. … … 251 251 252 252 </dd> 253 <dt><big> DPyObject <u>opIndex</u>(DPyObject <i>key</i>);253 <dt><big>PydObject <u>opIndex</u>(PydObject <i>key</i>); 254 254 </big></dt> 255 255 <dd>Equivalent to o[key] in Python. … … 257 257 258 258 </dd> 259 <dt><big> DPyObject <u>opIndex</u>(char[] <i>key</i>);259 <dt><big>PydObject <u>opIndex</u>(char[] <i>key</i>); 260 260 </big></dt> 261 261 <dd>Equivalent to o['key'] in Python; usually only makes sense for … … 265 265 266 266 </dd> 267 <dt><big> DPyObject <u>opIndex</u>(int <i>i</i>);267 <dt><big>PydObject <u>opIndex</u>(int <i>i</i>); 268 268 </big></dt> 269 269 <dd>Equivalent to o[i] in Python; usually only makes sense for sequences. … … 271 271 272 272 </dd> 273 <dt><big>void <u>opIndexAssign</u>( DPyObject <i>value</i>, DPyObject <i>key</i>);273 <dt><big>void <u>opIndexAssign</u>(PydObject <i>value</i>, PydObject <i>key</i>); 274 274 </big></dt> 275 275 <dd>Equivalent to o[key] = value in Python. … … 277 277 278 278 </dd> 279 <dt><big>void <u>opIndexAssign</u>( DPyObject <i>value</i>, char[] <i>key</i>);279 <dt><big>void <u>opIndexAssign</u>(PydObject <i>value</i>, char[] <i>key</i>); 280 280 </big></dt> 281 281 <dd>Equivalent to o['key'] = value in Python. Usually only makes sense for … … 285 285 286 286 </dd> 287 <dt><big>void <u>opIndexAssign</u>( DPyObject <i>value</i>, int <i>i</i>);287 <dt><big>void <u>opIndexAssign</u>(PydObject <i>value</i>, int <i>i</i>); 288 288 </big></dt> 289 289 <dd>Equivalent to o[i] = value in Python. Usually only makes sense for … … 293 293 294 294 </dd> 295 <dt><big>void <u>delItem</u>( DPyObject <i>key</i>);295 <dt><big>void <u>delItem</u>(PydObject <i>key</i>); 296 296 </big></dt> 297 297 <dd>Equivalent to del o[key] in Python. … … 315 315 316 316 </dd> 317 <dt><big> DPyObject <u>opSlice</u>(int <i>i1</i>, int <i>i2</i>);317 <dt><big>PydObject <u>opSlice</u>(int <i>i1</i>, int <i>i2</i>); 318 318 </big></dt> 319 319 <dd>Equivalent to o[i1:i2] in Python. … … 321 321 322 322 </dd> 323 <dt><big> DPyObject <u>opSlice</u>();323 <dt><big>PydObject <u>opSlice</u>(); 324 324 </big></dt> 325 325 <dd>Equivalent to o[:] in Python. … … 327 327 328 328 </dd> 329 <dt><big>void <u>opSliceAssign</u>( DPyObject <i>v</i>, int <i>i1</i>, int <i>i2</i>);329 <dt><big>void <u>opSliceAssign</u>(PydObject <i>v</i>, int <i>i1</i>, int <i>i2</i>); 330 330 </big></dt> 331 331 <dd>Equivalent to o[i1:i2] = v in Python. … … 333 333 334 334 </dd> 335 <dt><big>void <u>opSliceAssign</u>( DPyObject <i>v</i>);335 <dt><big>void <u>opSliceAssign</u>(PydObject <i>v</i>); 336 336 </big></dt> 337 337 <dd>Equivalent to o[:] = v in Python. … … 351 351 352 352 </dd> 353 <dt><big>int <u>opApply</u>(int delegate(inout DPyObject) <i>dg</i>);353 <dt><big>int <u>opApply</u>(int delegate(inout PydObject) <i>dg</i>); 354 354 </big></dt> 355 355 <dd>Iterates over the items in a collection, be they the items in a 356 356 sequence, keys in a dictionary, or some other iteration defined for the 357 DPyObject's type.358 359 <br><br> 360 361 </dd> 362 <dt><big>int <u>opApply</u>(int delegate(inout DPyObject, inout DPyObject) <i>dg</i>);363 </big></dt> 364 <dd>Iterate over (key, value) pairs in a dictionary. If the DPyObject is not357 PydObject's type. 358 359 <br><br> 360 361 </dd> 362 <dt><big>int <u>opApply</u>(int delegate(inout PydObject, inout PydObject) <i>dg</i>); 363 </big></dt> 364 <dd>Iterate over (key, value) pairs in a dictionary. If the PydObject is not 365 365 a dict, this simply does nothing. (It iterates over no items.) You 366 366 should not attempt to modify the dictionary while iterating through it, … … 371 371 372 372 </dd> 373 <dt><big> DPyObject <u>opAdd</u>(DPyObject <i>o</i>);374 </big></dt> 375 <dd><br><br> 376 </dd> 377 <dt><big> DPyObject <u>opSub</u>(DPyObject <i>o</i>);378 </big></dt> 379 <dd><br><br> 380 </dd> 381 <dt><big> DPyObject <u>opMul</u>(DPyObject <i>o</i>);382 </big></dt> 383 <dd><br><br> 384 </dd> 385 <dt><big> DPyObject <u>opMul</u>(int <i>count</i>);373 <dt><big>PydObject <u>opAdd</u>(PydObject <i>o</i>); 374 </big></dt> 375 <dd><br><br> 376 </dd> 377 <dt><big>PydObject <u>opSub</u>(PydObject <i>o</i>); 378 </big></dt> 379 <dd><br><br> 380 </dd> 381 <dt><big>PydObject <u>opMul</u>(PydObject <i>o</i>); 382 </big></dt> 383 <dd><br><br> 384 </dd> 385 <dt><big>PydObject <u>opMul</u>(int <i>count</i>); 386 386 </big></dt> 387 387 <dd>Sequence repetition … … 389 389 390 390 </dd> 391 <dt><big> DPyObject <u>opDiv</u>(DPyObject <i>o</i>);392 </big></dt> 393 <dd><br><br> 394 </dd> 395 <dt><big> DPyObject <u>floorDiv</u>(DPyObject <i>o</i>);396 </big></dt> 397 <dd><br><br> 398 </dd> 399 <dt><big> DPyObject <u>opMod</u>(DPyObject <i>o</i>);400 </big></dt> 401 <dd><br><br> 402 </dd> 403 <dt><big> DPyObject <u>divmod</u>(DPyObject <i>o</i>);404 </big></dt> 405 <dd><br><br> 406 </dd> 407 <dt><big> DPyObject <u>pow</u>(DPyObject <i>o1</i>, DPyObject <i>o2</i> = null);408 </big></dt> 409 <dd><br><br> 410 </dd> 411 <dt><big> DPyObject <u>opPos</u>();412 </big></dt> 413 <dd><br><br> 414 </dd> 415 <dt><big> DPyObject <u>opNeg</u>();416 </big></dt> 417 <dd><br><br> 418 </dd> 419 <dt><big> DPyObject <u>abs</u>();420 </big></dt> 421 <dd><br><br> 422 </dd> 423 <dt><big> DPyObject <u>opCom</u>();424 </big></dt> 425 <dd><br><br> 426 </dd> 427 <dt><big> DPyObject <u>opShl</u>(DPyObject <i>o</i>);428 </big></dt> 429 <dd><br><br> 430 </dd> 431 <dt><big> DPyObject <u>opShr</u>(DPyObject <i>o</i>);432 </big></dt> 433 <dd><br><br> 434 </dd> 435 <dt><big> DPyObject <u>opAnd</u>(DPyObject <i>o</i>);436 </big></dt> 437 <dd><br><br> 438 </dd> 439 <dt><big> DPyObject <u>opXor</u>(DPyObject <i>o</i>);440 </big></dt> 441 <dd><br><br> 442 </dd> 443 <dt><big> DPyObject <u>opOr</u>(DPyObject <i>o</i>);444 </big></dt> 445 <dd><br><br> 446 </dd> 447 <dt><big> DPyObject <u>opAddAssign</u>(DPyObject <i>o</i>);448 </big></dt> 449 <dd><br><br> 450 </dd> 451 <dt><big> DPyObject <u>opSubAssign</u>(DPyObject <i>o</i>);452 </big></dt> 453 <dd><br><br> 454 </dd> 455 <dt><big> DPyObject <u>opMulAssign</u>(DPyObject <i>o</i>);456 </big></dt> 457 <dd><br><br> 458 </dd> 459 <dt><big> DPyObject <u>opMulAssign</u>(int <i>count</i>);391 <dt><big>PydObject <u>opDiv</u>(PydObject <i>o</i>); 392 </big></dt> 393 <dd><br><br> 394 </dd> 395 <dt><big>PydObject <u>floorDiv</u>(PydObject <i>o</i>); 396 </big></dt> 397 <dd><br><br> 398 </dd> 399 <dt><big>PydObject <u>opMod</u>(PydObject <i>o</i>); 400 </big></dt> 401 <dd><br><br> 402 </dd> 403 <dt><big>PydObject <u>divmod</u>(PydObject <i>o</i>); 404 </big></dt> 405 <dd><br><br> 406 </dd> 407 <dt><big>PydObject <u>pow</u>(PydObject <i>o1</i>, PydObject <i>o2</i> = null); 408 </big></dt> 409 <dd><br><br> 410 </dd> 411 <dt><big>PydObject <u>opPos</u>(); 412 </big></dt> 413 <dd><br><br> 414 </dd> 415 <dt><big>PydObject <u>opNeg</u>(); 416 </big></dt> 417 <dd><br><br> 418 </dd> 419 <dt><big>PydObject <u>abs</u>(); 420 </big></dt> 421 <dd><br><br> 422 </dd> 423 <dt><big>PydObject <u>opCom</u>(); 424 </big></dt> 425 <dd><br><br> 426 </dd> 427 <dt><big>PydObject <u>opShl</u>(PydObject <i>o</i>); 428 </big></dt> 429 <dd><br><br> 430 </dd> 431 <dt><big>PydObject <u>opShr</u>(PydObject <i>o</i>); 432 </big></dt> 433 <dd><br><br> 434 </dd> 435 <dt><big>PydObject <u>opAnd</u>(PydObject <i>o</i>); 436 </big></dt> 437 <dd><br><br> 438 </dd> 439 <dt><big>PydObject <u>opXor</u>(PydObject <i>o</i>); 440 </big></dt> 441 <dd><br><br> 442 </dd> 443 <dt><big>PydObject <u>opOr</u>(PydObject <i>o</i>); 444 </big></dt> 445 <dd><br><br> 446 </dd> 447 <dt><big>PydObject <u>opAddAssign</u>(PydObject <i>o</i>); 448 </big></dt> 449 <dd><br><br> 450 </dd> 451 <dt><big>PydObject <u>opSubAssign</u>(PydObject <i>o</i>); 452 </big></dt> 453 <dd><br><br> 454 </dd> 455 <dt><big>PydObject <u>opMulAssign</u>(PydObject <i>o</i>); 456 </big></dt> 457 <dd><br><br> 458 </dd> 459 <dt><big>PydObject <u>opMulAssign</u>(int <i>count</i>); 460 460 </big></dt> 461 461 <dd>In-place sequence repetition … … 463 463 464 464 </dd> 465 <dt><big> DPyObject <u>opDivAssign</u>(DPyObject <i>o</i>);466 </big></dt> 467 <dd><br><br> 468 </dd> 469 <dt><big> DPyObject <u>floorDivAssign</u>(DPyObject <i>o</i>);470 </big></dt> 471 <dd><br><br> 472 </dd> 473 <dt><big> DPyObject <u>opModAssign</u>(DPyObject <i>o</i>);474 </big></dt> 475 <dd><br><br> 476 </dd> 477 <dt><big> DPyObject <u>powAssign</u>(DPyObject <i>o1</i>, DPyObject <i>o2</i> = null);478 </big></dt> 479 <dd><br><br> 480 </dd> 481 <dt><big> DPyObject <u>opShlAssign</u>(DPyObject <i>o</i>);482 </big></dt> 483 <dd><br><br> 484 </dd> 485 <dt><big> DPyObject <u>opShrAssign</u>(DPyObject <i>o</i>);486 </big></dt> 487 <dd><br><br> 488 </dd> 489 <dt><big> DPyObject <u>opAndAssign</u>(DPyObject <i>o</i>);490 </big></dt> 491 <dd><br><br> 492 </dd> 493 <dt><big> DPyObject <u>opXorAssign</u>(DPyObject <i>o</i>);494 </big></dt> 495 <dd><br><br> 496 </dd> 497 <dt><big> DPyObject <u>opOrAssign</u>(DPyObject <i>o</i>);498 </big></dt> 499 <dd><br><br> 500 </dd> 501 <dt><big> DPyObject <u>asInt</u>();502 </big></dt> 503 <dd><br><br> 504 </dd> 505 <dt><big> DPyObject <u>asLong</u>();506 </big></dt> 507 <dd><br><br> 508 </dd> 509 <dt><big> DPyObject <u>asFloat</u>();465 <dt><big>PydObject <u>opDivAssign</u>(PydObject <i>o</i>); 466 </big></dt> 467 <dd><br><br> 468 </dd> 469 <dt><big>PydObject <u>floorDivAssign</u>(PydObject <i>o</i>); 470 </big></dt> 471 <dd><br><br> 472 </dd> 473 <dt><big>PydObject <u>opModAssign</u>(PydObject <i>o</i>); 474 </big></dt> 475 <dd><br><br> 476 </dd> 477 <dt><big>PydObject <u>powAssign</u>(PydObject <i>o1</i>, PydObject <i>o2</i> = null); 478 </big></dt> 479 <dd><br><br> 480 </dd> 481 <dt><big>PydObject <u>opShlAssign</u>(PydObject <i>o</i>); 482 </big></dt> 483 <dd><br><br> 484 </dd> 485 <dt><big>PydObject <u>opShrAssign</u>(PydObject <i>o</i>); 486 </big></dt> 487 <dd><br><br> 488 </dd> 489 <dt><big>PydObject <u>opAndAssign</u>(PydObject <i>o</i>); 490 </big></dt> 491 <dd><br><br> 492 </dd> 493 <dt><big>PydObject <u>opXorAssign</u>(PydObject <i>o</i>); 494 </big></dt> 495 <dd><br><br> 496 </dd> 497 <dt><big>PydObject <u>opOrAssign</u>(PydObject <i>o</i>); 498 </big></dt> 499 <dd><br><br> 500 </dd> 501 <dt><big>PydObject <u>asInt</u>(); 502 </big></dt> 503 <dd><br><br> 504 </dd> 505 <dt><big>PydObject <u>asLong</u>(); 506 </big></dt> 507 <dd><br><br> 508 </dd> 509 <dt><big>PydObject <u>asFloat</u>(); 510 510 </big></dt> 511 511 <dd><br><br> … … 527 527 <dd><br><br> 528 528 </dd> 529 <dt><big> DPyObject <u>opCat</u>(DPyObject <i>o</i>);529 <dt><big>PydObject <u>opCat</u>(PydObject <i>o</i>); 530 530 </big></dt> 531 531 <dd>Sequence concatenation … … 533 533 534 534 </dd> 535 <dt><big> DPyObject <u>opCatAssign</u>(DPyObject <i>o</i>);535 <dt><big>PydObject <u>opCatAssign</u>(PydObject <i>o</i>); 536 536 </big></dt> 537 537 <dd>In-place sequence concatenation … … 539 539 540 540 </dd> 541 <dt><big>int <u>count</u>( DPyObject <i>v</i>);542 </big></dt> 543 <dd><br><br> 544 </dd> 545 <dt><big>int <u>index</u>( DPyObject <i>v</i>);546 </big></dt> 547 <dd><br><br> 548 </dd> 549 <dt><big> DPyObject <u>asList</u>();550 </big></dt> 551 <dd>Converts any iterable DPyObject to a list552 <br><br> 553 554 </dd> 555 <dt><big> DPyObject <u>asTuple</u>();556 </big></dt> 557 <dd>Converts any iterable DPyObject to a tuple558 <br><br> 559 560 </dd> 561 <dt><big>bool <u>opIn_r</u>( DPyObject <i>v</i>);541 <dt><big>int <u>count</u>(PydObject <i>v</i>); 542 </big></dt> 543 <dd><br><br> 544 </dd> 545 <dt><big>int <u>index</u>(PydObject <i>v</i>); 546 </big></dt> 547 <dd><br><br> 548 </dd> 549 <dt><big>PydObject <u>asList</u>(); 550 </big></dt> 551 <dd>Converts any iterable PydObject to a list 552 <br><br> 553 554 </dd> 555 <dt><big>PydObject <u>asTuple</u>(); 556 </big></dt> 557 <dd>Converts any iterable PydObject to a tuple 558 <br><br> 559 560 </dd> 561 <dt><big>bool <u>opIn_r</u>(PydObject <i>v</i>); 562 562 </big></dt> 563 563 <dd>Same as "<i>v</i> in this" in Python. … … 565 565 566 566 </dd> 567 <dt><big>bool <u>hasKey</u>( DPyObject <i>key</i>);567 <dt><big>bool <u>hasKey</u>(PydObject <i>key</i>); 568 568 </big></dt> 569 569 <dd>Same as opIn_r … … 583 583 584 584 </dd> 585 <dt><big> DPyObject <u>keys</u>();586 </big></dt> 587 <dd><br><br> 588 </dd> 589 <dt><big> DPyObject <u>values</u>();590 </big></dt> 591 <dd><br><br> 592 </dd> 593 <dt><big> DPyObject <u>items</u>();585 <dt><big>PydObject <u>keys</u>(); 586 </big></dt> 587 <dd><br><br> 588 </dd> 589 <dt><big>PydObject <u>values</u>(); 590 </big></dt> 591 <dd><br><br> 592 </dd> 593 <dt><big>PydObject <u>items</u>(); 594 594 </big></dt> 595 595 <dd><br><br> trunk/infrastructure/pyd/class_wrap.d
r48 r49 45 45 46 46 // This is split out in case I ever want to make a subtype of a wrapped class. 47 template DPyObject_HEAD(T) {47 template PydWrapObject_HEAD(T) { 48 48 mixin PyObject_HEAD; 49 49 T d_obj; … … 54 54 extern(C) 55 55 struct wrapped_class_object { 56 mixin DPyObject_HEAD!(T);56 mixin PydWrapObject_HEAD!(T); 57 57 } 58 58 } … … 333 333 */ 334 334 static void iter(iter_t) () { 335 DPySC_Ready();335 PydStackContext_Ready(); 336 336 wrapped_class_type!(T).tp_iter = &wrapped_iter!(T, T.opApply, int function(iter_t)).iter; 337 337 } … … 345 345 static PyMethodDef empty = { null, null, 0, null }; 346 346 alias wrapped_method_list!(T) list; 347 PydStackContext_Ready(); 347 348 list[length-1].ml_name = name ~ \0; 348 349 list[length-1].ml_meth = cast(PyCFunction)&wrapped_iter!(T, fn, int function(iter_t)).iter; … … 369 370 pragma(msg, "finalize_class: " ~ name); 370 371 371 assert( DPy_Module_p !is null, "Must initialize module before wrapping classes.");372 char[] module_name = toString(PyModule_GetName( DPy_Module_p));372 assert(Pyd_Module_p !is null, "Must initialize module before wrapping classes."); 373 char[] module_name = toString(PyModule_GetName(Pyd_Module_p)); 373 374 // Fill in missing values 374 375 type.ob_type = PyType_Type_p(); … … 401 402 static if (is(typeof(&T.opApply))) { 402 403 if (type.tp_iter is null) { 403 DPySC_Ready();404 PydStackContext_Ready(); 404 405 type.tp_iter = &wrapped_iter!(T, T.opApply).iter; 405 406 } … … 425 426 } 426 427 Py_INCREF(cast(PyObject*)&type); 427 PyModule_AddObject( DPy_Module_p, name, cast(PyObject*)&type);428 PyModule_AddObject(Pyd_Module_p, name, cast(PyObject*)&type); 428 429 is_wrapped!(T) = true; 429 430 wrapped_classes[typeid(T)] = true; trunk/infrastructure/pyd/def.d
r45 r49 37 37 PyObject* m_module; 38 38 39 PyObject* DPy_Module_p() {39 PyObject* Pyd_Module_p() { 40 40 return m_module; 41 41 } trunk/infrastructure/pyd/func_wrap.d
r45 r49 38 38 39 39 // Builds a Python callable object from a delegate or function pointer. 40 PyObject* DPyFunc_FromDG(T) (T dg) {40 PyObject* PydFunc_FromDelegate(T) (T dg) { 41 41 alias wrapped_class_type!(T) type; 42 42 alias wrapped_class_object!(T) obj; … … 46 46 type.tp_dealloc = &wrapped_methods!(T).wrapped_dealloc; 47 47 type.tp_basicsize = obj.sizeof; 48 type.tp_name = " DPyFunc";48 type.tp_name = "PydFunc"; 49 49 type.tp_call = &wrapped_func_call!(T).call; 50 50 PyType_Ready(&type); … … 124 124 template wrapped_func_call(fn_t) { 125 125 alias ReturnType!(fn_t) RT; 126 // The entry for the tp_call slot of the DPyFunc types.126 // The entry for the tp_call slot of the PydFunc types. 127 127 // (Or: What gets called when you pass a delegate or function pointer to 128 128 // Python.) … … 232 232 //----------------------------------------------------------------------------- 233 233 // The steps involved when calling this function are as follows: 234 // 1) An instance of DPyWrappedFunc is made, and the callable placed within.234 // 1) An instance of PydWrappedFunc is made, and the callable placed within. 235 235 // 2) The delegate type Dg is broken into its constituent parts. 236 // 3) These parts are used to get the proper overload of DPyWrappedFunc.fn237 // 4) A delegate to DPyWrappedFunc.fn is returned.236 // 3) These parts are used to get the proper overload of PydWrappedFunc.fn 237 // 4) A delegate to PydWrappedFunc.fn is returned. 238 238 // 5) When fn is called, it attempts to cram the arguments into the callable. 239 239 // If Python objects to this, an exception is raised. Note that this means … … 241 241 // detected at runtime. 242 242 243 Dg DPyCallable_AsDelegate(Dg) (PyObject* c) {243 Dg PydCallable_AsDelegate(Dg) (PyObject* c) { 244 244 return _pycallable_asdgT!(Dg).func(c); 245 245 } … … 250 250 251 251 Dg func(PyObject* c) { 252 auto f = new DPyWrappedFunc(c);252 auto f = new PydWrappedFunc(c); 253 253 254 254 return &f.fn!(Tr, Info); … … 257 257 258 258 private 259 class DPyWrappedFunc {259 class PydWrappedFunc { 260 260 PyObject* callable; 261 261 trunk/infrastructure/pyd/iteration.d
r45 r49 41 41 42 42 // This exception is for yielding a PyObject* from within a StackContext. 43 class DPyYield : Exception {43 class PydYield : Exception { 44 44 PyObject* m_py; 45 45 this(PyObject* py) { … … 51 51 52 52 // Creates an iterator object from an object. 53 PyObject* DPySC_FromWrapped(T, alias Iter = T.opApply, iter_t = typeof(&Iter)) (T obj) {53 PyObject* PydStackContext_FromWrapped(T, alias Iter = T.opApply, iter_t = typeof(&Iter)) (T obj) { 54 54 // Get the number of args the opApply's delegate argument takes 55 55 alias ParameterTypeTuple!(iter_t) IInfo; … … 65 65 66 66 t(delegate int(inout Info i) { 67 StackContext.throwYield(new DPyYield(PyTuple_FromItems(i)));67 StackContext.throwYield(new PydYield(PyTuple_FromItems(i))); 68 68 return 0; 69 69 }); … … 79 79 // Returns an iterator object for this class 80 80 extern (C) 81 PyObject* iter (PyObject* _self) {81 PyObject* iter(PyObject* _self) { 82 82 return exception_catcher({ 83 83 wrap_object* self = cast(wrap_object*)_self; 84 84 85 return DPySC_FromWrapped!(T, Iter, iter_t)(self.d_obj);85 return PydStackContext_FromWrapped!(T, Iter, iter_t)(self.d_obj); 86 86 }); 87 87 } … … 92 92 PyObject* sc_iternext(PyObject* _self) { 93 93 return exception_catcher(delegate PyObject*() { 94 alias wrapped_class_object!(StackContext) DPySC_object;95 DPySC_object* self = cast(DPySC_object*)_self;94 alias wrapped_class_object!(StackContext) PydSC_object; 95 PydSC_object* self = cast(PydSC_object*)_self; 96 96 97 97 try { … … 104 104 // The StackContext class yields values by throwing an exception. 105 105 // We catch it and pass the converted value into Python. 106 catch ( DPyYield y) {106 catch (PydYield y) { 107 107 return y.item(); 108 108 } … … 112 112 113 113 /// Readies the iterator class if it hasn't been already. 114 void DPySC_Ready() {114 void PydStackContext_Ready() { 115 115 alias wrapped_class_type!(StackContext) type; 116 alias wrapped_class_object!(StackContext) DPySC_object;116 alias wrapped_class_object!(StackContext) PydSC_object; 117 117 118 118 if (!is_wrapped!(StackContext)) { … … 120 120 //type.tp_new = &wrapped_methods!(StackContext).wrapped_new; 121 121 //type.tp_dealloc = &wrapped_methods!(StackContext).wrapped_dealloc; 122 type.tp_basicsize = DPySC_object.sizeof;122 type.tp_basicsize = PydSC_object.sizeof; 123 123 type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; 124 124 //type.tp_doc = ""; trunk/infrastructure/pyd/make_object.d
r45 r49 31 31 * The former is handled by d_type, the latter by _py. The py function is 32 32 * provided as a convenience to directly convert a D type into an instance of 33 * DPyObject.33 * PydObject. 34 34 */ 35 35 module pyd.make_object; … … 39 39 private import std.string; 40 40 41 private import pyd. dpyobject;41 private import pyd.pydobject; 42 42 private import pyd.class_wrap; 43 43 private import pyd.func_wrap; … … 67 67 * argument. If the passed argument is a PyObject*, this "steals" the 68 68 * reference. (In other words, it returns the PyObject* without changing its 69 * reference count.) If the passed argument is a DPyObject, this returns a new70 * reference to whatever the DPyObject holds a reference to.69 * reference count.) If the passed argument is a PydObject, this returns a new 70 * reference to whatever the PydObject holds a reference to. 71 71 * 72 72 * If the passed argument can't be converted to a PyObject, a Python … … 132 132 return dict; 133 133 } else static if (is(T == delegate) || is(T == function)) { 134 return DPyFunc_FromDG!(T)(t);135 } else static if (is(T : DPyObject)) {134 return PydFunc_FromDelegate!(T)(t); 135 } else static if (is(T : PydObject)) { 136 136 PyObject* temp = t.ptr(); 137 137 Py_INCREF(temp); … … 174 174 * Constructs an object based on the type of the argument passed in. 175 175 * 176 * For example, calling py(10) would return a DPyObject holding the value 10.177 * 178 * Calling this with a DPyObject will return back a reference to the very same179 * DPyObject.176 * For example, calling py(10) would return a PydObject holding the value 10. 177 * 178 * Calling this with a PydObject will return back a reference to the very same 179 * PydObject. 180 180 * 181 181 * Calling this with a PyObject* will "steal" the reference. 182 182 */ 183 DPyObject py(T) (T t) {184 static if(is(T : DPyObject)) {183 PydObject py(T) (T t) { 184 static if(is(T : PydObject)) { 185 185 return t; 186 186 } else { 187 return new DPyObject(_py(t));187 return new PydObject(_py(t)); 188 188 } 189 189 } … … 192 192 * An exception class used by d_type. 193 193 */ 194 class DPyConversionException : Exception {194 class PydConversionException : Exception { 195 195 this(char[] msg) { super(msg); } 196 196 } … … 204 204 *assert(n == 20);) 205 205 * 206 * This throws a DPyConversionException if the PyObject can't be converted to206 * This throws a PydConversionException if the PyObject can't be converted to 207 207 * the given D type. 208 208 */ … … 214 214 // 215 215 // This also means that: 216 // (1) Conversion to DPyObject will construct an object and return that.216 // (1) Conversion to PydObject will construct an object and return that. 217 217 // (2) Any integral type smaller than a C_long (which is usually just 218 218 // an int, meaning short and byte) will use the bool conversion. … … 220 220 static if (is(PyObject* : T)) { 221 221 return o; 222 } else static if (is( DPyObject : T)) {223 return new DPyObject(o, true);222 } else static if (is(PydObject : T)) { 223 return new PydObject(o, true); 224 224 } else static if (is(T == void)) { 225 225 if (o != Py_None) could_not_convert!(T)(o); … … 236 236 } else static if (is(T == delegate)) { 237 237 if (PyCallable_Check(o)) { 238 return DPyCallable_AsDelegate!(T)(o);238 return PydCallable_AsDelegate!(T)(o); 239 239 } else could_not_convert!(T)(o); 240 240 /+ … … 310 310 } 311 311 d_typename = typeid(T).toString(); 312 throw new DPyConversionException(312 throw new PydConversionException( 313 313 "Couldn't convert Python type '" ~ 314 314 py_typename ~ trunk/infrastructure/pyd/pyd.d
r45 r49 30 30 public import pyd.class_wrap; 31 31 //public import pyd.ctor_wrap; 32 public import pyd. dpyobject;32 public import pyd.pydobject; 33 33 public import pyd.exception; 34 34 public import pyd.func_wrap; trunk/infrastructure/pyd/pydobject.d
r45 r49 20 20 SOFTWARE. 21 21 */ 22 module pyd. dpyobject;22 module pyd.pydobject; 23 23 24 24 private import std.c.stdio; … … 39 39 * $(LINK2 http://docs.python.org/api/api.html, The Python/C API) 40 40 */ 41 class DPyObject {41 class PydObject { 42 42 protected: 43 43 PyObject* m_ptr; … … 48 48 * o = The PyObject to wrap. 49 49 * borrowed = Whether o is a _borrowed reference. Instances 50 * of DPyObject always own their references.50 * of PydObject always own their references. 51 51 * Therefore, Py_INCREF will be called if borrowed is 52 52 * $(D_KEYWORD true). … … 54 54 this(PyObject* o, bool borrowed=false) { 55 55 if (o is null) handle_exception(); 56 // DPyObject always owns its references56 // PydObject always owns its references 57 57 if (borrowed) Py_INCREF(o); 58 58 m_ptr = o; 59 59 } 60 60 61 /// The default constructor constructs an instance of the Py_None DPyObject.61 /// The default constructor constructs an instance of the Py_None PydObject. 62 62 this() { this(Py_None, true); } 63 63 … … 77 77 * fp = The file object to _print to. std.c.stdio.stdout by default. 78 78 * raw = If $(D_KEYWORD true), prints the "str" representation of the 79 * DPyObject, and uses the "repr" otherwise. Defaults to79 * PydObject, and uses the "repr" otherwise. Defaults to 80 80 * $(D_KEYWORD false). 81 81 * Bugs: This does not seem to work, raising an AccessViolation. Meh. … … 95 95 96 96 /// Same as _hasattr(this, attr_name) in Python. 97 bool hasattr( DPyObject attr_name) {97 bool hasattr(PydObject attr_name) { 98 98 return PyObject_HasAttr(m_ptr, attr_name.m_ptr) == 1; 99 99 } 100 100 101 101 /// Same as _getattr(this, attr_name) in Python. 102 DPyObject getattr(char[] attr_name) {103 return new DPyObject(PyObject_GetAttrString(m_ptr, attr_name ~ \0));102 PydObject getattr(char[] attr_name) { 103 return new PydObject(PyObject_GetAttrString(m_ptr, attr_name ~ \0)); 104 104 } 105 105 106 106 /// Same as _getattr(this, attr_name) in Python. 107 DPyObject getattr(DPyObject attr_name) {108 return new DPyObject(PyObject_GetAttr(m_ptr, attr_name.m_ptr));107 PydObject getattr(PydObject attr_name) { 108 return new PydObject(PyObject_GetAttr(m_ptr, attr_name.m_ptr)); 109 109 } 110 110 … … 112 112 * Same as _setattr(this, attr_name, v) in Python. 113 113 */ 114 void setattr(char[] attr_name, DPyObject v) {114 void setattr(char[] attr_name, PydObject v) { 115 115 if (PyObject_SetAttrString(m_ptr, attr_name ~ \0, v.m_ptr) == -1) 116 116 handle_exception(); … … 120 120 * Same as _setattr(this, attr_name, v) in Python. 121 121 */ 122 void setattr( DPyObject attr_name, DPyObject v) {122 void setattr(PydObject attr_name, PydObject v) { 123 123 if (PyObject_SetAttr(m_ptr, attr_name.m_ptr, v.m_ptr) == -1) 124 124 handle_exception(); … … 136 136 * Same as del this.attr_name in Python. 137 137 */ 138 void delattr( DPyObject attr_name) {138 void delattr(PydObject attr_name) { 139 139 if (PyObject_DelAttr(m_ptr, attr_name.m_ptr) == -1) 140 140 handle_exception(); … … 144 144 * Exposes Python object comparison to D. Same as cmp(this, rhs) in Python. 145 145 */ 146 int opCmp( DPyObject rhs) {146 int opCmp(PydObject rhs) { 147 147 // This function happily maps exactly to opCmp 148 148 int res = PyObject_Compare(m_ptr, rhs.m_ptr); … … 155 155 * Exposes Python object equality check to D. 156 156 */ 157 bool opEquals( DPyObject rhs) {157 bool opEquals(PydObject rhs) { 158 158 int res = PyObject_Compare(m_ptr, rhs.m_ptr); 159 159 handle_exception(); … … 162 162 163 163 /// Same as _repr(this) in Python. 164 DPyObject repr() {165 return new DPyObject(PyObject_Repr(m_ptr));164 PydObject repr() { 165 return new PydObject(PyObject_Repr(m_ptr)); 166 166 } 167 167 168 168 /// Same as _str(this) in Python. 169 DPyObject str() {170 return new DPyObject(PyObject_Str(m_ptr));171 } 172 /// Allows use of DPyObject in writef via %s169 PydObject str() { 170 return new PydObject(PyObject_Str(m_ptr)); 171 } 172 /// Allows use of PydObject in writef via %s 173 173 char[] toString() { 174 174 return d_type!(char[])(m_ptr); … … 176 176 177 177 /// Same as _unicode(this) in Python. 178 DPyObject unicode() {179 return new DPyObject(PyObject_Unicode(m_ptr));178 PydObject unicode() { 179 return new PydObject(PyObject_Unicode(m_ptr)); 180 180 } 181 181 182 182 /// Same as isinstance(this, cls) in Python. 183 bool isInstance( DPyObject cls) {183 bool isInstance(PydObject cls) { 184 184 int res = PyObject_IsInstance(m_ptr, cls.m_ptr); 185 185 if (res == -1) handle_exception(); … … 188 188 189 189 /// Same as issubclass(this, cls) in Python. Only works if this is a class. 190 bool isSubclass( DPyObject cls) {190 bool isSubclass(PydObject cls) { 191 191 int res = PyObject_IsSubclass(m_ptr, cls.m_ptr); 192 192 if (res == -1) handle_exception(); … … 200 200 201 201 /** 202 * Calls the DPyObject.202 * Calls the PydObject. 203 203 * Params: 204 * args = Should be a DPyTuple of the arguments to pass. Omit to204 * args = Should be a PydTuple of the arguments to pass. Omit to 205 205 * call with no arguments. 206 * Returns: Whatever the function DPyObject returns.207 */ 208 DPyObject opCall(DPyObject args=null) {209 return new DPyObject(PyObject_CallObject(m_ptr, args is null ? null : args.m_ptr));206 * Returns: Whatever the function PydObject returns. 207 */ 208 PydObject opCall(PydObject args=null) { 209 return new PydObject(PyObject_CallObject(m_ptr, args is null ? null : args.m_ptr)); 210 210 } 211 211 212 212 /** 213 * Calls the DPyObject with positional and keyword arguments.213 * Calls the PydObject with positional and keyword arguments. 214 214 * Params: 215 * args = Positional arguments. Should be a DPyTuple. Pass an empty216 * DPyTuple for no positional arguments.217 * kw = Keyword arguments. Should be a DPyDict.218 * Returns: Whatever the function DPyObject returns.219 */ 220 DPyObject opCall(DPyObject args, DPyObject kw) {221 return new DPyObject(PyObject_Call(m_ptr, args.m_ptr, kw.m_ptr));215 * args = Positional arguments. Should be a PydTuple. Pass an empty 216 * PydTuple for no positional arguments. 217 * kw = Keyword arguments. Should be a PydDict. 218 * Returns: Whatever the function PydObject returns. 219 */ 220 PydObject opCall(PydObject args, PydObject kw) { 221 return new PydObject(PyObject_Call(m_ptr, args.m_ptr, kw.m_ptr)); 222 222 } 223 223 … … 225 225 * 226 226 */ 227 DPyObject method(char[] name, DPyObject args=null) {228 // Get the method DPyObject227 PydObject method(char[] name, PydObject args=null) { 228 // Get the method PydObject 229 229 PyObject* m = PyObject_GetAttrString(m_ptr, name ~ \0); 230 230 PyObject* self_tuple, args_tuple, result; … … 249 249 Py_DECREF(args_tuple); 250 250 // Return the result. 251 return new DPyObject(result);252 } 253 254 DPyObject method(char[] name, DPyObject args, DPyObject kw) {255 // Get the method DPyObject251 return new PydObject(result); 252 } 253 254 PydObject method(char[] name, PydObject args, PydObject kw) { 255 // Get the method PydObject 256 256 PyObject* m = PyObject_GetAttrString(m_ptr, name ~ \0); 257 257 PyObject* self_tuple, args_tuple, result; … … 270 270 Py_DECREF(args_tuple); 271 271 // Return the result. 272 return new DPyObject(result);272 return new PydObject(result); 273 273 } 274 274 … … 293 293 294 294 /** 295 * Gets the _type of this DPyObject. Same as _type(this) in Python.296 * Returns: The _type DPyObject of this DPyObject.297 */ 298 DPyObject type() {299 return new DPyObject(PyObject_Type(m_ptr));300 } 301 302 /** 303 * The _length of this DPyObject. Same as _len(this) in Python.295 * Gets the _type of this PydObject. Same as _type(this) in Python. 296 * Returns: The _type PydObject of this PydObject. 297 */ 298 PydObject type() { 299 return new PydObject(PyObject_Type(m_ptr)); 300 } 301 302 /** 303 * The _length of this PydObject. Same as _len(this) in Python. 304 304 */ 305 305 int length() { … … 312 312 313 313 /// Same as _dir(this) in Python. 314 DPyObject dir() {315 return new DPyObject(PyObject_Dir(m_ptr));314 PydObject dir() { 315 return new PydObject(PyObject_Dir(m_ptr)); 316 316 } 317 317 … … 320 320 //---------- 321 321 /// Equivalent to o[_key] in Python. 322 DPyObject opIndex(DPyObject key) {323 return new DPyObject(PyObject_GetItem(m_ptr, key.m_ptr));322 PydObject opIndex(PydObject key) { 323 return new PydObject(PyObject_GetItem(m_ptr, key.m_ptr)); 324 324 } 325 325 /** … … 327 327 * mappings. 328 328 */ 329 DPyObject opIndex(char[] key) {330 return new DPyObject(PyMapping_GetItemString(m_ptr, key ~ \0));329 PydObject opIndex(char[] key) { 330 return new PydObject(PyMapping_GetItemString(m_ptr, key ~ \0)); 331 331 } 332 332 /// Equivalent to o[_i] in Python; usually only makes sense for sequences. 333 DPyObject opIndex(int i) {334 return new DPyObject(PySequence_GetItem(m_ptr, i));333 PydObject opIndex(int i) { 334 return new PydObject(PySequence_GetItem(m_ptr, i)); 335 335 } 336 336 337 337 /// Equivalent to o[_key] = _value in Python. 338 void opIndexAssign( DPyObject value, DPyObject key) {338 void opIndexAssign(PydObject value, PydObject key) { 339 339 if (PyObject_SetItem(m_ptr, key.m_ptr, value.m_ptr) == -1) 340 340 handle_exception(); … … 344 344 * mappings. 345 345 */ 346 void opIndexAssign( DPyObject value, char[] key) {346 void opIndexAssign(PydObject value, char[] key) { 347 347 if (PyMapping_SetItemString(m_ptr, key ~ \0, value.m_ptr) == -1) 348 348 handle_exception(); … … 352 352 * sequences. 353 353 */ 354 void opIndexAssign( DPyObject value, int i) {354 void opIndexAssign(PydObject value, int i) { 355 355 if (PySequence_SetItem(m_ptr, i, value.m_ptr) == -1) 356 356 handle_exception(); … … 358 358 359 359 /// Equivalent to del o[_key] in Python. 360 void delItem( DPyObject key) {360 void delItem(PydObject key) { 361 361 if (PyObject_DelItem(m_ptr, key.m_ptr) == -1) 362 362 handle_exception(); … … 383 383 //--------- 384 384 /// Equivalent to o[_i1:_i2] in Python. 385 DPyObject opSlice(int i1, int i2) {386 return new DPyObject(PySequence_GetSlice(m_ptr, i1, i2));385 PydObject opSlice(int i1, int i2) { 386 return new PydObject(PySequence_GetSlice(m_ptr, i1, i2)); 387 387 } 388 388 /// Equivalent to o[:] in Python. 389 DPyObject opSlice() {389 PydObject opSlice() { 390 390 return this.opSlice(0, this.length()); 391 391 } 392 392 /// Equivalent to o[_i1:_i2] = _v in Python. 393 void opSliceAssign( DPyObject v, int i1, int i2) {393 void opSliceAssign(PydObject v, int i1, int i2) { 394 394 if (PySequence_SetSlice(m_ptr, i1, i1, v.m_ptr) == -1) 395 395 handle_exception(); 396 396 } 397 397 /// Equivalent to o[:] = _v in Python. 398 void opSliceAssign( DPyObject v) {398 void opSliceAssign(PydObject v) { 399 399 this.opSliceAssign(v, 0, this.length()); 400 400 } … … 416 416 * Iterates over the items in a collection, be they the items in a 417 417 * sequence, keys in a dictionary, or some other iteration defined for the 418 * DPyObject's type.419 */ 420 int opApply(int delegate(inout DPyObject) dg) {418 * PydObject's type. 419 */ 420 int opApply(int delegate(inout PydObject) dg) { 421 421 PyObject* iterator = PyObject_GetIter(m_ptr); 422 422 PyObject* item; 423 423 int result = 0; 424 DPyObject o;424 PydObject o; 425 425 426 426 if (iterator == null) { … … 430 430 item = PyIter_Next(iterator); 431 431 while (item) { 432 o = new DPyObject(item);432 o = new PydObject(item); 433 433 result = dg(o); 434 434 Py_DECREF(item); … … 445 445 446 446 /** 447 * Iterate over (key, value) pairs in a dictionary. If the DPyObject is not447 * Iterate over (key, value) pairs in a dictionary. If the PydObject is not 448 448 * a dict, this simply does nothing. (It iterates over no items.) You 449 449 * should not attempt to modify the dictionary while iterating through it, … … 451 451 * iterating through it is an especially bad idea. 452 452 */ 453 int opApply(int delegate(inout DPyObject, inout DPyObject) dg) {453 int opApply(int delegate(inout PydObject, inout PydObject) dg) { 454 454 PyObject* key, value; 455 455 version(Python_2_5_Or_Later) { … … 459 459 } 460 460 int result = 0; 461 DPyObject k, v;461 PydObject k, v; 462 462 463 463 while (PyDict_Next(m_ptr, &pos, &key, &value)) { 464 k = new DPyObject(key, true);465 v = new DPyObject(value, true);464 k = new PydObject(key, true); 465 v = new PydObject(value, true); 466 466 result = dg(k, v); 467 467 if (result) break; … … 475 475 //------------ 476 476 /// 477 DPyObject opAdd(DPyObject o) {478 return new DPyObject(PyNumber_Add(m_ptr, o.m_ptr));479 } 480 /// 481 DPyObject opSub(DPyObject o) {482 return new DPyObject(PyNumber_Subtract(m_ptr, o.m_ptr));483 } 484 /// 485 DPyObject opMul(DPyObject o) {486 return new DPyObject(PyNumber_Multiply(m_ptr, o.m_ptr));477 PydObject opAdd(PydObject o) { 478 return new PydObject(PyNumber_Add(m_ptr, o.m_ptr)); 479 } 480 /// 481 PydObject opSub(PydObject o) { 482 return new PydObject(PyNumber_Subtract(m_ptr, o.m_ptr)); 483 } 484 /// 485 PydObject opMul(PydObject o) { 486 return new PydObject(PyNumber_Multiply(m_ptr, o.m_ptr)); 487 487 } 488 488 /// Sequence repetition 489 DPyObject opMul(int count) {490 return new DPyObject(PySequence_Repeat(m_ptr, count));491 } 492 /// 493 DPyObject opDiv(DPyObject o) {494 return new DPyObject(PyNumber_Divide(m_ptr, o.m_ptr));495 } 496 /// 497 DPyObject floorDiv(DPyObject o) {498 return new DPyObject(PyNumber_FloorDivide(m_ptr, o.m_ptr));499 } 500 /// 501 DPyObject opMod(DPyObject o) {502 return new DPyObject(PyNumber_Remainder(m_ptr, o.m_ptr));503 } 504 /// 505 DPyObject divmod(DPyObject o) {506 return new DPyObject(PyNumber_Divmod(m_ptr, o.m_ptr));507 } 508 /// 509 DPyObject pow(DPyObject o1, DPyObject o2=null) {510 return new DPyObject(PyNumber_Power(m_ptr, o1.m_ptr, (o2 is null) ? Py_None : o2.m_ptr));511 } 512 /// 513 DPyObject opPos() {514 return new DPyObject(PyNumber_Positive(m_ptr));515 } 516 /// 517 DPyObject opNeg() {518 return new DPyObject(PyNumber_Negative(m_ptr));519 } 520 /// 521 DPyObject abs() {522 return new DPyObject(PyNumber_Absolute(m_ptr));523 } 524 /// 525 DPyObject opCom() {526 return new DPyObject(PyNumber_Invert(m_ptr));527 } 528 /// 529 DPyObject opShl(DPyObject o) {530 return new DPyObject(PyNumber_Lshift(m_ptr, o.m_ptr));531 } 532 /// 533 DPyObject opShr(DPyObject o) {534 return new DPyObject(PyNumber_Rshift(m_ptr, o.m_ptr));535 } 536 /// 537 DPyObject opAnd(DPyObject o) {538 return new DPyObject(PyNumber_And(m_ptr, o.m_ptr));539 } 540 /// 541 DPyObject opXor(DPyObject o) {542 return new DPyObject(PyNumber_Xor(m_ptr, o.m_ptr));543 } 544 /// 545 DPyObject opOr(DPyObject o) {546 return new DPyObject(PyNumber_Or(m_ptr, o.m_ptr));489 PydObject opMul(int count) { 490 return new PydObject(PySequence_Repeat(m_ptr, count)); 491 } 492 /// 493 PydObject opDiv(PydObject o) { 494 return new PydObject(PyNumber_Divide(m_ptr, o.m_ptr)); 495 } 496 /// 497 PydObject floorDiv(PydObject o) { 498 return new PydObject(PyNumber_FloorDivide(m_ptr, o.m_ptr)); 499 } 500 /// 501 PydObject opMod(PydObject o) { 502 return new PydObject(PyNumber_Remainder(m_ptr, o.m_ptr)); 503 } 504 /// 505 PydObject divmod(PydObject o) { 506 return new PydObject(PyNumber_Divmod(m_ptr, o.m_ptr)); 507 } 508 /// 509 PydObject pow(PydObject o1, PydObject o2=null) { 510 return new PydObject(PyNumber_Power(m_ptr, o1.m_ptr, (o2 is null) ? Py_None : o2.m_ptr)); 511 } 512 /// 513 PydObject opPos() { 514 return new PydObject(PyNumber_Positive(m_ptr)); 515 } 516 /// 517 PydObject opNeg() { 518 return new PydObject(PyNumber_Negative(m_ptr)); 519 } 520 /// 521 PydObject abs() { 522 return new PydObject(PyNumber_Absolute(m_ptr)); 523 } 524 /// 525 PydObject opCom() { 526 return new PydObject(PyNumber_Invert(m_ptr)); 527 } 528 /// 529 PydObject opShl(PydObject o) { 530 return new PydObject(PyNumber_Lshift(m_ptr, o.m_ptr)); 531 } 532 /// 533 PydObject opShr(PydObject o) { 534 return new PydObject(PyNumber_Rshift(m_ptr, o.m_ptr)); 535 } 536 /// 537 PydObject opAnd(PydObject o) { 538 return new PydObject(PyNumber_And(m_ptr, o.m_ptr)); 539 } 540 /// 541 PydObject opXor(PydObject o) { 542 return new PydObject(PyNumber_Xor(m_ptr, o.m_ptr)); 543 } 544 /// 545 PydObject opOr(PydObject o) { 546 return new PydObject(PyNumber_Or(m_ptr, o.m_ptr)); 547 547 } 548 548 … … 554 554 555 555 // A useful wrapper for most of the in-place operators 556 private DPyObject557 inplace(op_t op, DPyObject rhs) {556 private PydObject 557 inplace(op_t op, PydObject rhs) { 558 558 if (PyType_HasFeature(m_ptr.ob_type, Py_TPFLAGS_HAVE_INPLACEOPS)) { 559 559 op(m_ptr, rhs.m_ptr); … … 568 568 } 569 569 /// 570 DPyObject opAddAssign(DPyObject o) {570 PydObject opAddAssign(PydObject o) { 571 571 return inplace(&PyNumber_InPlaceAdd, o); 572 572 } 573 573 /// 574 DPyObject opSubAssign(DPyObject o) {574 PydObject opSubAssign(PydObject o) { 575 575 return inplace(&PyNumber_InPlaceSubtract, o); 576 576 } 577 577 /// 578 DPyObject opMulAssign(DPyObject o) {578 PydObject opMulAssign(PydObject o) { 579 579 return inplace(&PyNumber_InPlaceMultiply, o); 580 580 } 581 581 /// In-place sequence repetition 582 DPyObject opMulAssign(int count) {582 PydObject opMulAssign(int count) { 583 583 if (PyType_HasFeature(m_ptr.ob_type, Py_TPFLAGS_HAVE_INPLACEOPS)) { 584 584 PySequence_InPlaceRepeat(m_ptr, count); … … 593 593 } 594 594 /// 595 DPyObject opDivAssign(DPyObject o) {595 PydObject opDivAssign(PydObject o) { 596 596 return inplace(&PyNumber_InPlaceDivide, o); 597 597 } 598 598 /// 599 DPyObject floorDivAssign(DPyObject o) {599 PydObject floorDivAssign(PydObject o) { 600 600 return inplace(&PyNumber_InPlaceFloorDivide, o); 601 601 } 602 602 /// 603 DPyObject opModAssign(DPyObject o) {603 PydObject opModAssign(PydObject o) { 604 604 return inplace(&PyNumber_InPlaceRemainder, o); 605 605 } 606 606 /// 607 DPyObject powAssign(DPyObject o1, DPyObject o2=null) {607 PydObject powAssign(PydObject o1, PydObject o2=null) { 608 608 if (PyType_HasFeature(m_ptr.ob_type, Py_TPFLAGS_HAVE_INPLACEOPS)) { 609 609 PyNumber_InPlacePower(m_ptr, o1.m_ptr, (o2 is null) ? Py_None : o2.m_ptr); … … 618 618 } 619 619 /// 620 DPyObject opShlAssign(DPyObject o) {620 PydObject opShlAssign(PydObject o) { 621 621 return inplace(&PyNumber_InPlaceLshift, o); 622 622 } 623 623 /// 624 DPyObject opShrAssign(DPyObject o) {624 PydObject opShrAssign(PydObject o) { 625 625 return inplace(&PyNumber_InPlaceRshift, o); 626 626 } 627 627 /// 628 DPyObject opAndAssign(DPyObject o) {628 PydObject opAndAssign(PydObject o) { 629 629 return inplace(&PyNumber_InPlaceAnd, o); 630 630 } 631 631 /// 632 DPyObject opXorAssign(DPyObject o) {632 PydObject opXorAssign(PydObject o) { 633 633 return inplace(&PyNumber_InPlaceXor, o); 634 634 } 635 635 /// 636 DPyObject opOrAssign(DPyObject o) {636 PydObject opOrAssign(PydObject o) { 637 637 return inplace(&PyNumber_InPlaceOr, o); 638 638 } … … 642 642 //----------------- 643 643 /// 644 DPyObject asInt() {645 return new DPyObject(PyNumber_Int(m_ptr));646 } 647 /// 648 DPyObject asLong() {649 return new DPyObject(PyNumber_Long(m_ptr));650 } 651 /// 652 DPyObject asFloat() {653 return new DPyObject(PyNumber_Float(m_ptr));644 PydObject asInt() { 645 return new PydObject(PyNumber_Int(m_ptr)); 646 } 647 /// 648 PydObject asLong() { 649 return new PydObject(PyNumber_Long(m_ptr)); 650 } 651 /// 652 PydObject asFloat() { 653 return new PydObject(PyNumber_Float(m_ptr)); 654 654 } 655 655 /// … … 675 675 676 676 /// Sequence concatenation 677 DPyObject opCat(DPyObject o) {678 return new DPyObject(PySequence_Concat(m_ptr, o.m_ptr));677 PydObject opCat(PydObject o) { 678 return new PydObject(PySequence_Concat(m_ptr, o.m_ptr)); 679 679 } 680 680 /// In-place sequence concatenation 681 DPyObject opCatAssign(DPyObject o) {681 PydObject opCatAssign(PydObject o) { 682 682 return inplace(&PySequence_InPlaceConcat, o); 683 683 } 684 684 /// 685 int count( DPyObject v) {685 int count(PydObject v) { 686 686 int result = PySequence_Count(m_ptr, v.m_ptr); 687 687 if (result == -1) handle_exception(); … … 689 689 } 690 690 /// 691 int index( DPyObject v) {691 int index(PydObject v) { 692 692 int result = PySequence_Index(m_ptr, v.m_ptr); 693 693 if (result == -1) handle_exception(); 694 694 return result; 695 695 } 696 /// Converts any iterable DPyObject to a list697 DPyObject asList() {698 return new DPyObject(PySequence_List(m_ptr));699 } 700 /// Converts any iterable DPyObject to a tuple701 DPyObject asTuple() {702 return new DPyObject(PySequence_Tuple(m_ptr));696 /// Converts any iterable PydObject to a list 697 PydObject asList() { 698 return new PydObject(PySequence_List(m_ptr)); 699 } 700 /// Converts any iterable PydObject to a tuple 701 PydObject asTuple() { 702 return new PydObject(PySequence_Tuple(m_ptr)); 703 703 } 704 704 /+ … … 711 711 return temp; 712 712 } else { 713 PyErr_SetString(PyExc_RuntimeError, "Cannot convert non-PyUnicode DPyObject to wchar[].");713 PyErr_SetString(PyExc_RuntimeError, "Cannot convert non-PyUnicode PydObject to wchar[]."); 714 714 handle_exception(); 715 715 } 716 716 } 717 717 // Added by list: 718 void insert(int i, DPyObject item) { assert(false); }719 void append( DPyObject item) { assert(false); }718 void insert(int i, PydObject item) { assert(false); } 719 void append(PydObject item) { assert(false); } 720 720 void sort() { assert(false); } 721 721 void reverse() { assert(false); } … … 726 726 //----------------- 727 727 /// Same as "v in this" in Python. 728 bool opIn_r( DPyObject v) {728 bool opIn_r(PydObject v) { 729 729 int result = PySequence_Contains(m_ptr, v.m_ptr); 730 730 if (result == -1) handle_exception(); … … 732 732 } 733 733 /// Same as opIn_r 734 bool hasKey( DPyObject key) { return this.opIn_r(key); }734 bool hasKey(PydObject key) { return this.opIn_r(key); } 735 735 /// Same as "'v' in this" in Python. 736 736 bool opIn_r(char[] key) { … … 744 744 } 745 745 /// 746 DPyObject keys() {747 return new DPyObject(PyMapping_Keys(m_ptr));748 } 749 /// 750 DPyObject values() {751 return new DPyObject(PyMapping_Values(m_ptr));752 } 753 /// 754 DPyObject items() {755 return new DPyObject(PyMapping_Items(m_ptr));746 PydObject keys() { 747 return new PydObject(PyMapping_Keys(m_ptr)); 748 } 749 /// 750 PydObject values() { 751 return new PydObject(PyMapping_Values(m_ptr)); 752 } 753 /// 754 PydObject items() { 755 return new PydObject(PyMapping_Items(m_ptr)); 756 756 } 757 757 /+ 758 758 // Added by dict 759 759 void clear() { assert(false); } 760 DPyObject copy() { assert(false); }761 void update( DPyObject o, bool over_ride=true) { assert(false); }760 PydObject copy() { assert(false); } 761 void update(PydObject o, bool over_ride=true) { assert(false); } 762 762 +/ 763 763 }
