Skip to content

Commit 597dfc5

Browse files
committed
tutorial update
[SVN r40734]
1 parent 6a3085a commit 597dfc5

File tree

13 files changed

+686
-806
lines changed

13 files changed

+686
-806
lines changed

doc/tutorial/doc/html/index.html

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@
33
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
44
<title>Chapter 1. python 1.0</title>
55
<link rel="stylesheet" href="boostbook.css" type="text/css">
6-
<meta name="generator" content="DocBook XSL Stylesheets V1.72.0">
6+
<meta name="generator" content="DocBook XSL Stylesheets V1.66.1">
77
<link rel="start" href="index.html" title="Chapter 1. python 1.0">
8-
<link rel="next" href="python/hello.html" title="Building Hello World">
8+
<link rel="next" href="python/hello.html" title=" Building Hello World">
99
</head>
1010
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
11-
<table cellpadding="2" width="100%">
11+
<table cellpadding="2" width="100%"><tr>
1212
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
1313
<td align="center"><a href="../../../../../../index.htm">Home</a></td>
1414
<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
1515
<td align="center"><a href="../../../../../../people/people.htm">People</a></td>
1616
<td align="center"><a href="../../../../../../more/faq.htm">FAQ</a></td>
1717
<td align="center"><a href="../../../../../../more/index.htm">More</a></td>
18-
</table>
18+
</tr></table>
1919
<hr>
20-
<div class="spirit-nav"><a accesskey="n" href="python/hello.html"><img src="images/next.png" alt="Next"></a></div>
20+
<div class="spirit-nav"><a accesskey="n" href="python/hello.html"><img src="../../../../../../doc/html/images/next.png" alt="Next"></a></div>
2121
<div class="chapter" lang="en">
2222
<div class="titlepage"><div>
2323
<div><h2 class="title">
@@ -31,7 +31,7 @@
3131
<div><p class="copyright">Copyright © 2002-2005 Joel
3232
de Guzman, David Abrahams</p></div>
3333
<div><div class="legalnotice">
34-
<a name="id2632684"></a><p>
34+
<a name="id385505"></a><p>
3535
Distributed under the Boost Software License, Version 1.0. (See accompanying
3636
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">
3737
http://www.boost.org/LICENSE_1_0.txt </a>)
@@ -93,10 +93,10 @@
9393
code takes on the look of a kind of declarative interface definition language
9494
(IDL).
9595
</p>
96-
<a name="quickstart.hello_world"></a><h3>
97-
<a name="id2595112"></a>
96+
<a name="quickstart.hello_world"></a><h2>
97+
<a name="id455837"></a>
9898
Hello World
99-
</h3>
99+
</h2>
100100
<p>
101101
Following C/C++ tradition, let's start with the "hello, world". A
102102
C++ Function:
@@ -112,10 +112,10 @@
112112
</p>
113113
<pre class="programlisting">
114114
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
115-
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
116115

117-
<span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">hello</span><span class="special">)</span>
116+
<span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">hello_ext</span><span class="special">)</span>
118117
<span class="special">{</span>
118+
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
119119
<span class="identifier">def</span><span class="special">(</span><span class="string">"greet"</span><span class="special">,</span> <span class="identifier">greet</span><span class="special">);</span>
120120
<span class="special">}</span>
121121
</pre>
@@ -126,7 +126,7 @@
126126
<p>
127127
</p>
128128
<pre class="programlisting">
129-
<span class="special">&gt;&gt;&gt;</span> <span class="keyword">import</span> <span class="identifier">hello</span>
129+
<span class="special">&gt;&gt;&gt;</span> <span class="keyword">import</span> <span class="identifier">hello_ext</span>
130130
<span class="special">&gt;&gt;&gt;</span> <span class="keyword">print</span> <span class="identifier">hello</span><span class="special">.</span><span class="identifier">greet</span><span class="special">()</span>
131131
<span class="identifier">hello</span><span class="special">,</span> <span class="identifier">world</span>
132132
</pre>
@@ -136,19 +136,19 @@
136136
<p>
137137
</p>
138138
<p>
139-
<span class="emphasis"><em><span class="bold"><strong>Next stop... Building your Hello World
140-
module from start to finish...</strong></span></em></span>
139+
<span class="emphasis"><em><span class="bold"><b>Next stop... Building your Hello World
140+
module from start to finish...</b></span></em></span>
141141
</p>
142142
<p>
143143
</p>
144144
</blockquote></div>
145145
</div>
146146
</div>
147147
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
148-
<td align="left"><small><p>Last revised: May 18, 2007 at 15:46:01 GMT</p></small></td>
148+
<td align="left"><p><small>Last revised: November 04, 2007 at 00:10:08 GMT</small></p></td>
149149
<td align="right"><small></small></td>
150150
</tr></table>
151151
<hr>
152-
<div class="spirit-nav"><a accesskey="n" href="python/hello.html"><img src="images/next.png" alt="Next"></a></div>
152+
<div class="spirit-nav"><a accesskey="n" href="python/hello.html"><img src="../../../../../../doc/html/images/next.png" alt="Next"></a></div>
153153
</body>
154154
</html>

doc/tutorial/doc/html/python/embedding.html

Lines changed: 52 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@
33
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
44
<title>Embedding</title>
55
<link rel="stylesheet" href="../boostbook.css" type="text/css">
6-
<meta name="generator" content="DocBook XSL Stylesheets V1.72.0">
6+
<meta name="generator" content="DocBook XSL Stylesheets V1.66.1">
77
<link rel="start" href="../index.html" title="Chapter 1. python 1.0">
88
<link rel="up" href="../index.html" title="Chapter 1. python 1.0">
9-
<link rel="prev" href="object.html" title="Object Interface">
9+
<link rel="prev" href="object.html" title=" Object Interface">
1010
<link rel="next" href="iterators.html" title="Iterators">
1111
</head>
1212
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13-
<table cellpadding="2" width="100%">
13+
<table cellpadding="2" width="100%"><tr>
1414
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
1515
<td align="center"><a href="../../../../../../../index.htm">Home</a></td>
1616
<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
1717
<td align="center"><a href="../../../../../../../people/people.htm">People</a></td>
1818
<td align="center"><a href="../../../../../../../more/faq.htm">FAQ</a></td>
1919
<td align="center"><a href="../../../../../../../more/index.htm">More</a></td>
20-
</table>
20+
</tr></table>
2121
<hr>
2222
<div class="spirit-nav">
23-
<a accesskey="p" href="object.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="iterators.html"><img src="../images/next.png" alt="Next"></a>
23+
<a accesskey="p" href="object.html"><img src="../../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="iterators.html"><img src="../../../../../../../doc/html/images/next.png" alt="Next"></a>
2424
</div>
2525
<div class="section" lang="en">
2626
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
@@ -39,28 +39,28 @@
3939
a lot easier and, in a future version, it may become unnecessary to touch the
4040
Python/C API at all. So stay tuned... <span class="inlinemediaobject"><img src="../images/smiley.png" alt="smiley"></span>
4141
</p>
42-
<a name="embedding.building_embedded_programs"></a><h3>
43-
<a name="id2654982"></a>
42+
<a name="embedding.building_embedded_programs"></a><h2>
43+
<a name="id471088"></a>
4444
Building embedded programs
45-
</h3>
45+
</h2>
4646
<p>
4747
To be able to embed python into your programs, you have to link to both Boost.Python's
4848
as well as Python's own runtime library.
4949
</p>
5050
<p>
5151
Boost.Python's library comes in two variants. Both are located in Boost's
52-
<code class="literal">/libs/python/build/bin-stage</code> subdirectory. On Windows, the
53-
variants are called <code class="literal">boost_python.lib</code> (for release builds)
54-
and <code class="literal">boost_python_debug.lib</code> (for debugging). If you can't
52+
<tt class="literal">/libs/python/build/bin-stage</tt> subdirectory. On Windows, the
53+
variants are called <tt class="literal">boost_python.lib</tt> (for release builds)
54+
and <tt class="literal">boost_python_debug.lib</tt> (for debugging). If you can't
5555
find the libraries, you probably haven't built Boost.Python yet. See <a href="../../../../building.html" target="_top">Building and Testing</a> on how to do this.
5656
</p>
5757
<p>
58-
Python's library can be found in the <code class="literal">/libs</code> subdirectory
58+
Python's library can be found in the <tt class="literal">/libs</tt> subdirectory
5959
of your Python directory. On Windows it is called pythonXY.lib where X.Y is
6060
your major Python version number.
6161
</p>
6262
<p>
63-
Additionally, Python's <code class="literal">/include</code> subdirectory has to be added
63+
Additionally, Python's <tt class="literal">/include</tt> subdirectory has to be added
6464
to your include path.
6565
</p>
6666
<p>
@@ -81,44 +81,46 @@
8181
&lt;library-path&gt;$(PYTHON_LIB_PATH)
8282
&lt;find-library&gt;$(PYTHON_EMBEDDED_LIBRARY) ;
8383
</pre>
84-
<a name="embedding.getting_started"></a><h3>
85-
<a name="id2655076"></a>
84+
<a name="embedding.getting_started"></a><h2>
85+
<a name="id471193"></a>
8686
Getting started
87-
</h3>
87+
</h2>
8888
<p>
8989
Being able to build is nice, but there is nothing to build yet. Embedding the
9090
Python interpreter into one of your C++ programs requires these 4 steps:
9191
</p>
9292
<div class="orderedlist"><ol type="1">
9393
<li>
94-
#include <code class="literal">&lt;boost/python.hpp&gt;</code><br><br>
94+
#include <tt class="literal">&lt;boost/python.hpp&gt;</tt>
9595
</li>
9696
<li>
9797
Call <a href="http://www.python.org/doc/current/api/initialization.html#l2h-652" target="_top">Py_Initialize</a>()
98-
to start the interpreter and create the <code class="literal"><span class="underline">_main</span>_</code>
99-
module.<br><br>
100-
</li>
98+
to start the interpreter and create the <tt class="literal"><span class="underline">_main</span>_</tt>
99+
module.
100+
</li>
101101
<li>
102-
Call other Python C API routines to use the interpreter.<br><br>
103-
</li>
102+
Call other Python C API routines to use the interpreter.
103+
</li>
104104
</ol></div>
105-
<div class="sidebar">
106-
<p class="title"><b></b></p>
107-
<p>
108-
<span class="inlinemediaobject"><img src="../images/note.png" alt="note"></span> <span class="bold"><strong>Note that at this time you must
109-
not call <a href="http://www.python.org/doc/current/api/initialization.html#l2h-656" target="_top">Py_Finalize</a>()
110-
to stop the interpreter. This may be fixed in a future version of boost.python.</strong></span>
111-
</p>
112-
</div>
105+
<div class="note"><table border="0" summary="Note">
106+
<tr>
107+
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/html/images/note.png"></td>
108+
<th align="left">Note</th>
109+
</tr>
110+
<tr><td colspan="2" align="left" valign="top"><p>
111+
<span class="bold"><b>Note that at this time you must not call <a href="http://www.python.org/doc/current/api/initialization.html#l2h-656" target="_top">Py_Finalize</a>()
112+
to stop the interpreter. This may be fixed in a future version of boost.python.</b></span>
113+
</p></td></tr>
114+
</table></div>
113115
<p>
114116
(Of course, there can be other C++ code between all of these steps.)
115117
</p>
116118
<div class="blockquote"><blockquote class="blockquote">
117119
<p>
118120
</p>
119121
<p>
120-
<span class="emphasis"><em><span class="bold"><strong>Now that we can embed the interpreter in
121-
our programs, lets see how to put it to use...</strong></span></em></span>
122+
<span class="emphasis"><em><span class="bold"><b>Now that we can embed the interpreter in
123+
our programs, lets see how to put it to use...</b></span></em></span>
122124
</p>
123125
<p>
124126
</p>
@@ -128,18 +130,18 @@
128130
<a name="python.using_the_interpreter"></a>Using the interpreter</h3></div></div></div>
129131
<p>
130132
As you probably already know, objects in Python are reference-counted. Naturally,
131-
the <code class="literal">PyObject</code>s of the Python/C API are also reference-counted.
133+
the <tt class="literal">PyObject</tt>s of the Python/C API are also reference-counted.
132134
There is a difference however. While the reference-counting is fully automatic
133135
in Python, the Python<span class="emphasis"><em>C API requires you to do it [@http:</em></span>/www.python.org/doc/current/api/refcounts.html
134136
by hand]. This is messy and especially hard to get right in the presence
135137
of C++ exceptions. Fortunately Boost.Python provides the <a href="../../../../v2/handle.html" target="_top">handle</a>
136138
and <a href="../../../../v2/object.html" target="_top">object</a> class templates to
137139
automate the process.
138140
</p>
139-
<a name="using_the_interpreter.running_python_code"></a><h3>
140-
<a name="id2655255"></a>
141+
<a name="using_the_interpreter.running_python_code"></a><h2>
142+
<a name="id471356"></a>
141143
Running Python code
142-
</h3>
144+
</h2>
143145
<p>
144146
Boost.python provides three related functions to run Python code from C++.
145147
</p>
@@ -154,10 +156,10 @@
154156
and exec_file executes the code contained in the given file.
155157
</p>
156158
<p>
157-
The <code class="literal">globals</code> and <code class="literal">locals</code> parameters are
159+
The <tt class="literal">globals</tt> and <tt class="literal">locals</tt> parameters are
158160
Python dictionaries containing the globals and locals of the context in which
159161
to run the code. For most intents and purposes you can use the namespace
160-
dictionary of the <code class="literal"><span class="underline">_main</span>_</code>
162+
dictionary of the <tt class="literal"><span class="underline">_main</span>_</tt>
161163
module for both parameters.
162164
</p>
163165
<p>
@@ -171,7 +173,7 @@
171173
first), and returns it.
172174
</p>
173175
<p>
174-
Let's import the <code class="literal"><span class="underline">_main</span>_</code>
176+
Let's import the <tt class="literal"><span class="underline">_main</span>_</tt>
175177
module and run some Python code in its namespace:
176178
</p>
177179
<pre class="programlisting">
@@ -187,15 +189,15 @@
187189
This should create a file called 'hello.txt' in the current directory containing
188190
a phrase that is well-known in programming circles.
189191
</p>
190-
<a name="using_the_interpreter.manipulating_python_objects"></a><h3>
191-
<a name="id2655783"></a>
192+
<a name="using_the_interpreter.manipulating_python_objects"></a><h2>
193+
<a name="id471944"></a>
192194
Manipulating Python objects
193-
</h3>
195+
</h2>
194196
<p>
195197
Often we'd like to have a class to manipulate Python objects. But we have
196198
already seen such a class above, and in the <a href="object.html" target="_top">previous
197-
section</a>: the aptly named <code class="literal">object</code> class and its
198-
derivatives. We've already seen that they can be constructed from a <code class="literal">handle</code>.
199+
section</a>: the aptly named <tt class="literal">object</tt> class and its
200+
derivatives. We've already seen that they can be constructed from a <tt class="literal">handle</tt>.
199201
The following examples should further illustrate this fact:
200202
</p>
201203
<pre class="programlisting">
@@ -205,7 +207,7 @@
205207
<span class="keyword">int</span> <span class="identifier">five_squared</span> <span class="special">=</span> <span class="identifier">extract</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;(</span><span class="identifier">main_namespace</span><span class="special">[</span><span class="string">"result"</span><span class="special">]);</span>
206208
</pre>
207209
<p>
208-
Here we create a dictionary object for the <code class="literal"><span class="underline">_main</span>_</code>
210+
Here we create a dictionary object for the <tt class="literal"><span class="underline">_main</span>_</tt>
209211
module's namespace. Then we assign 5 squared to the result variable and read
210212
this variable from the dictionary. Another way to achieve the same result
211213
is to use eval instead, which returns the result directly:
@@ -214,10 +216,10 @@
214216
<span class="identifier">object</span> <span class="identifier">result</span> <span class="special">=</span> <span class="identifier">eval</span><span class="special">(</span><span class="string">"5 ** 2"</span><span class="special">);</span>
215217
<span class="keyword">int</span> <span class="identifier">five_squared</span> <span class="special">=</span> <span class="identifier">extract</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;(</span><span class="identifier">result</span><span class="special">);</span>
216218
</pre>
217-
<a name="using_the_interpreter.exception_handling"></a><h3>
218-
<a name="id2656116"></a>
219+
<a name="using_the_interpreter.exception_handling"></a><h2>
220+
<a name="id472316"></a>
219221
Exception handling
220-
</h3>
222+
</h2>
221223
<p>
222224
If an exception occurs in the evaluation of the python expression, <a href="../../../../v2/errors.html#error_already_set-spec" target="_top">error_already_set</a>
223225
is thrown:
@@ -235,7 +237,7 @@
235237
</span><span class="special">}</span>
236238
</pre>
237239
<p>
238-
The <code class="literal">error_already_set</code> exception class doesn't carry any
240+
The <tt class="literal">error_already_set</tt> exception class doesn't carry any
239241
information in itself. To find out more about the Python exception that occurred,
240242
you need to use the <a href="http://www.python.org/doc/api/exceptionHandling.html" target="_top">exception
241243
handling functions</a> of the Python<span class="emphasis"><em>C API in your catch-statement.
@@ -271,7 +273,7 @@
271273
</tr></table>
272274
<hr>
273275
<div class="spirit-nav">
274-
<a accesskey="p" href="object.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="iterators.html"><img src="../images/next.png" alt="Next"></a>
276+
<a accesskey="p" href="object.html"><img src="../../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="iterators.html"><img src="../../../../../../../doc/html/images/next.png" alt="Next"></a>
275277
</div>
276278
</body>
277279
</html>

0 commit comments

Comments
 (0)