root/trunk/raw_html/basics.html

Revision 102, 2.1 kB (checked in by KirkMcDonald, 2 years ago)

Updated docs with new class-wrapping API.

Line 
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <html>
3 <head>
4     <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
5     <link href="pyd.css" rel="stylesheet" type="text/css">
6     <title>Starting out with Pyd</title>
7 </head>
8
9 <body>
10 %(nav)s
11 <div id="content">
12
13 <h1>The basics</h1>
14
15 <h3>Module basics</h3>
16
17 <p>The most minimal working Pyd module looks something like this:</p>
18
19 <pre class="code"><span class="keyword">import</span> pyd.pyd;
20
21 <span class="keyword">extern</span> (C) <span class="keyword">void</span> PydMain() {
22     module_init();
23 }</pre>
24
25 <p>The first line imports Pyd:</p>
26
27 <pre class="code"><span class="keyword">import</span> pyd.pyd;</pre>
28
29 <p>The <code>pyd</code> module in the <code>pyd</code> package publicly imports all of the other components of Pyd.</p>
30
31 <p>The <code>PydMain</code> function is called when the module is imported by Python. You will call most of Pyd's API from here. At the very least, <code>PydMain</code> <em>must</em> contain a call to <code>module_init</code>. The <code>module_init</code> function has the following form:</p>
32
33 <p><code>PyObject* module_init(char[] <span class="arg">docstring</span>="");</code></p>
34
35 <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>
36
37 <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>wrap_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>wrap_class</code> in the wrong place will throw an assert.</p>
38
39 <p><code>PydMain</code> will catch any D exception that is thrown from inside it, and <a href="except_wrapping.html">safely pass that exception to Python</a>.</p>
40 </div>
41
42 </body>
43 </html>
Note: See TracBrowser for help on using the browser.