Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/python/doc/v2/module.html @ 29

Last change on this file since 29 was 29, checked in by landauf, 17 years ago

updated boost from 1_33_1 to 1_34_1

File size: 3.4 KB
Line 
1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2    <meta name="generator" content="HTML Tidy, see www.w3.org">
3    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
4    <link rel="stylesheet" type="text/css" href="../boost.css">
5
6    <title>Boost.Python - &lt;boost/python/module.hpp&gt;</title>
7
8    <table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
9    "header">
10      <tr>
11        <td valign="top" width="300">
12          <h3><a href="../../../../index.htm"><img height="86" width="277" alt=
13          "C++ Boost" src="../../../../boost.png" border="0"></a></h3>
14
15        <td valign="top">
16          <h1 align="center"><a href="../index.html">Boost.Python</a></h1>
17
18          <h2 align="center">Header &lt;boost/python/module.hpp&gt;</h2>
19    </table>
20    <hr>
21
22    <h2>Contents</h2>
23
24    <dl class="page-index">
25      <dt><a href="#introduction">Introduction</a>
26
27      <dt><a href="#macros">Macros</a>
28
29      <dd>
30        <dl class="page-index">
31          <dt><a href=
32          "#BOOST_PYTHON_MODULE-spec">BOOST_PYTHON_MODULE</a>
33        </dl>
34
35      <dt><a href="#examples">Example(s)</a>
36    </dl>
37    <hr>
38
39    <h2><a name="introduction"></a>Introduction</h2>
40
41    <p>This header provides the basic facilities needed to create a
42    Boost.Python extension module.
43
44    <h2><a name="macros"></a>Macros</h2>
45
46    <p><a name=
47    "BOOST_PYTHON_MODULE-spec"><code>BOOST_PYTHON_MODULE(name)</code></a>
48    is used to declare Python <a href=
49    "http://www.python.org/doc/2.2/ext/methodTable.html#SECTION003400000000000000000">
50    module initialization functions</a>. The <code>name</code> argument must
51    exactly match the name of the module to be initialized, and must conform to
52    Python's <a href=
53    "http://www.python.org/doc/2.2/ref/identifiers.html">identifier naming
54    rules</a>. Where you would normally write
55<pre>
56extern &quot;C&quot; void init<i>name</i>()
57{
58   ...
59}
60</pre>
61    Boost.Python modules should be initialized with
62<pre>
63BOOST_PYTHON_MODULE(<i>name</i>)
64{
65   ...
66}
67</pre>
68
69This macro generates two functions in the scope where it is used:
70<code>extern&nbsp;&quot;C&quot;&nbsp;void&nbsp;init<i>name</i>()</code>,
71and <code>void&nbsp;init_module_<i>name</i>()</code>, whose body must
72follow the macro invocation. <code>init_<i>name</i></code> passes
73<code>init_module_<i>name</i></code> to <code><a
74href="errors.html#handle_exception-spec">handle_exception</a>()</code> so
75that any C++ exceptions generated are safely processeed. During the
76body of <code>init_<i>name</i></code>, the current <code><a
77href="scope.html#scope-spec">scope</a></code> refers to the module
78being initialized.
79
80    <h2><a name="examples"></a>Example(s)</h2>
81
82    <p>C++ module definition:
83<pre>
84#include &lt;boost/python/module.hpp&gt;
85
86BOOST_PYTHON_MODULE(xxx)
87{
88    throw &quot;something bad happened&quot;
89}
90</pre>
91
92Interactive Python:
93<pre>
94&gt;&gt;&gt; import xxx
95Traceback (most recent call last):
96  File "<stdin>", line 1, in ?
97RuntimeError: Unidentifiable C++ Exception
98</pre>
99
100    <p>Revised
101    <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
102  13 November, 2002
103  <!--webbot bot="Timestamp" endspan i-checksum="39359" -->
104
105
106    <p><i>&copy; Copyright <a href="../../../../people/dave_abrahams.htm">Dave
107    Abrahams</a> 2002. </i> Distributed
108  under the Boost Software License, Version 1.0. (See accompanying file
109  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)</p>
110
Note: See TracBrowser for help on using the repository browser.