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 - <boost/python/module.hpp></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 <boost/python/module.hpp></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> |
---|
56 | extern "C" void init<i>name</i>() |
---|
57 | { |
---|
58 | ... |
---|
59 | } |
---|
60 | </pre> |
---|
61 | Boost.Python modules should be initialized with |
---|
62 | <pre> |
---|
63 | BOOST_PYTHON_MODULE(<i>name</i>) |
---|
64 | { |
---|
65 | ... |
---|
66 | } |
---|
67 | </pre> |
---|
68 | |
---|
69 | This macro generates two functions in the scope where it is used: |
---|
70 | <code>extern "C" void init<i>name</i>()</code>, |
---|
71 | and <code>void init_module_<i>name</i>()</code>, whose body must |
---|
72 | follow the macro invocation. <code>init_<i>name</i></code> passes |
---|
73 | <code>init_module_<i>name</i></code> to <code><a |
---|
74 | href="errors.html#handle_exception-spec">handle_exception</a>()</code> so |
---|
75 | that any C++ exceptions generated are safely processeed. During the |
---|
76 | body of <code>init_<i>name</i></code>, the current <code><a |
---|
77 | href="scope.html#scope-spec">scope</a></code> refers to the module |
---|
78 | being initialized. |
---|
79 | |
---|
80 | <h2><a name="examples"></a>Example(s)</h2> |
---|
81 | |
---|
82 | <p>C++ module definition: |
---|
83 | <pre> |
---|
84 | #include <boost/python/module.hpp> |
---|
85 | |
---|
86 | BOOST_PYTHON_MODULE(xxx) |
---|
87 | { |
---|
88 | throw "something bad happened" |
---|
89 | } |
---|
90 | </pre> |
---|
91 | |
---|
92 | Interactive Python: |
---|
93 | <pre> |
---|
94 | >>> import xxx |
---|
95 | Traceback (most recent call last): |
---|
96 | File "<stdin>", line 1, in ? |
---|
97 | RuntimeError: 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>© 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 | |
---|