|
28 | 28 | <div><div class="author"><h3 class="author"> |
29 | 29 | <span class="firstname">David</span> <span class="surname">Abrahams</span> |
30 | 30 | </h3></div></div> |
31 | | -<div><p class="copyright">Copyright © 2002-2005 Joel de Guzman, David Abrahams</p></div> |
| 31 | +<div><p class="copyright">Copyright © 2002-2005 Joel |
| 32 | + de Guzman, David Abrahams</p></div> |
32 | 33 | <div><div class="legalnotice"> |
33 | | -<a name="id442427"></a><p> |
34 | | - Distributed under the Boost Software License, Version 1.0. |
35 | | - (See accompanying file LICENSE_1_0.txt or copy at |
36 | | - <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top"> |
37 | | - http://www.boost.org/LICENSE_1_0.txt |
38 | | - </a>) |
39 | | - |
| 34 | +<a name="id427816"></a><p> |
| 35 | + Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 36 | + file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top"> |
| 37 | + http://www.boost.org/LICENSE_1_0.txt </a>) |
40 | 38 | </p> |
41 | 39 | </div></div> |
42 | 40 | </div></div> |
|
85 | 83 | <div class="titlepage"><div><div><h2 class="title" style="clear: both"> |
86 | 84 | <a name="python.quickstart"></a>QuickStart</h2></div></div></div> |
87 | 85 | <p> |
88 | | -The Boost Python Library is a framework for interfacing Python and |
89 | | -C++. It allows you to quickly and seamlessly expose C++ classes |
90 | | -functions and objects to Python, and vice-versa, using no special |
91 | | -tools -- just your C++ compiler. It is designed to wrap C++ interfaces |
92 | | -non-intrusively, so that you should not have to change the C++ code at |
93 | | -all in order to wrap it, making Boost.Python ideal for exposing |
94 | | -3rd-party libraries to Python. The library's use of advanced |
95 | | -metaprogramming techniques simplifies its syntax for users, so that |
96 | | -wrapping code takes on the look of a kind of declarative interface |
97 | | -definition language (IDL).</p> |
| 86 | + QuickStartThe Boost Python Library is a framework for interfacing Python and |
| 87 | + C++. It allows you to quickly and seamlessly expose C++ classes functions and |
| 88 | + objects to Python, and vice-versa, using no special tools -- just your C++ |
| 89 | + compiler. It is designed to wrap C++ interfaces non-intrusively, so that you |
| 90 | + should not have to change the C++ code at all in order to wrap it, making Boost.Python |
| 91 | + ideal for exposing 3rd-party libraries to Python. The library's use of advanced |
| 92 | + metaprogramming techniques simplifies its syntax for users, so that wrapping |
| 93 | + code takes on the look of a kind of declarative interface definition language |
| 94 | + (IDL). |
| 95 | + </p> |
98 | 96 | <a name="quickstart.hello_world"></a><h2> |
99 | | -<a name="id372086"></a>Hello World</h2> |
| 97 | +<a name="id372244"></a> |
| 98 | + Hello World |
| 99 | + </h2> |
100 | 100 | <p> |
101 | | -Following C/C++ tradition, let's start with the "hello, world". A C++ |
102 | | -Function:</p> |
103 | | -<pre class="programlisting"><tt class="literal"><span class="keyword">char</span><span class="keyword"> const</span><span class="special">*</span><span class="identifier"> greet</span><span class="special">()</span><span class="special"> |
104 | | -{</span><span class="keyword"> |
105 | | - return</span><span class="string"> "hello, world"</span><span class="special">;</span><span class="special"> |
106 | | -}</span></tt></pre> |
| 101 | + Following C/C++ tradition, let's start with the "hello, world". A |
| 102 | + C++ Function: |
| 103 | + </p> |
| 104 | +<pre class="programlisting"> |
| 105 | +<span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">greet</span><span class="special">()</span> |
| 106 | +<span class="special">{</span> |
| 107 | + <span class="keyword">return</span> <span class="string">"hello, world"</span><span class="special">;</span> |
| 108 | +<span class="special">}</span> |
| 109 | +</pre> |
107 | 110 | <p> |
108 | | -can be exposed to Python by writing a Boost.Python wrapper:</p> |
109 | | -<pre class="programlisting"><tt class="literal"><span class="preprocessor">#include</span><span class="special"> <</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">></span><span class="keyword"> |
110 | | -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><span class="identifier"> |
| 111 | + can be exposed to Python by writing a Boost.Python wrapper: |
| 112 | + </p> |
| 113 | +<pre class="programlisting"> |
| 114 | +<span class="preprocessor">#include</span> <span class="special"><</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">></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> |
111 | 116 |
|
112 | | -BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">hello</span><span class="special">)</span><span class="special"> |
113 | | -{</span><span class="identifier"> |
114 | | - def</span><span class="special">(</span><span class="string">"greet"</span><span class="special">,</span><span class="identifier"> greet</span><span class="special">);</span><span class="special"> |
115 | | -}</span></tt></pre> |
| 117 | +<span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">hello</span><span class="special">)</span> |
| 118 | +<span class="special">{</span> |
| 119 | + <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> |
| 120 | +<span class="special">}</span> |
| 121 | +</pre> |
116 | 122 | <p> |
117 | | -That's it. We're done. We can now build this as a shared library. The |
118 | | -resulting DLL is now visible to Python. Here's a sample Python session:</p> |
| 123 | + That's it. We're done. We can now build this as a shared library. The resulting |
| 124 | + DLL is now visible to Python. Here's a sample Python session: |
| 125 | + </p> |
119 | 126 | <p></p> |
120 | | -<pre class="programlisting"><tt class="literal"><span class="special">>>></span><span class="keyword"> import</span><span class="identifier"> hello</span><span class="special"> |
121 | | ->>></span><span class="keyword"> print</span><span class="identifier"> hello</span><span class="special">.</span><span class="identifier">greet</span><span class="special">()</span><span class="identifier"> |
122 | | -hello</span><span class="special">,</span><span class="identifier"> world</span></tt></pre> |
| 127 | +<pre class="programlisting"> |
| 128 | +<span class="special">>>></span> <span class="keyword">import</span> <span class="identifier">hello</span> |
| 129 | +<span class="special">>>></span> <span class="keyword">print</span> <span class="identifier">hello</span><span class="special">.</span><span class="identifier">greet</span><span class="special">()</span> |
| 130 | +<span class="identifier">hello</span><span class="special">,</span> <span class="identifier">world</span> |
| 131 | +</pre> |
123 | 132 | <p></p> |
124 | | -<div class="blockquote"><blockquote class="blockquote"><p><span class="emphasis"><em><span class="bold"><b>Next stop... Building your Hello World module from start to finish...</b></span></em></span></p></blockquote></div> |
| 133 | +<div class="blockquote"><blockquote class="blockquote"><p><span class="emphasis"><em><span class="bold"><b>Next stop... Building your Hello World module |
| 134 | + from start to finish...</b></span></em></span></p></blockquote></div> |
125 | 135 | </div> |
126 | 136 | </div> |
127 | 137 | <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> |
128 | | -<td align="left"><small><p>Last revised: July 12, 2005 at 07:50:43 GMT</p></small></td> |
| 138 | +<td align="left"><small><p>Last revised: October 31, 2005 at 18:46:06 GMT</p></small></td> |
129 | 139 | <td align="right"><small></small></td> |
130 | 140 | </tr></table> |
131 | 141 | <hr> |
|
0 commit comments