mirror of
https://github.com/boostorg/python.git
synced 2026-01-30 20:12:37 +00:00
138 lines
8.8 KiB
HTML
138 lines
8.8 KiB
HTML
<html>
|
||
<head>
|
||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||
<title>Chapter 1. python 1.0</title>
|
||
<link rel="stylesheet" href="boostbook.css" type="text/css">
|
||
<meta name="generator" content="DocBook XSL Stylesheets V1.65.1">
|
||
<link rel="home" href="index.html" title="Chapter 1. python 1.0">
|
||
<link rel="next" href="python/hello.html" title=" Building Hello World">
|
||
</head>
|
||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||
<table cellpadding="2" width="100%">
|
||
<td valign="top"><img alt="boost.png (6897 bytes)" width="277" height="86" src="../../boost.png"></td>
|
||
<td align="center"><a href="../../index.htm">Home</a></td>
|
||
<td align="center"><a href="libraries.html">Libraries</a></td>
|
||
<td align="center"><a href="../../people/people.htm">People</a></td>
|
||
<td align="center"><a href="../../more/faq.htm">FAQ</a></td>
|
||
<td align="center"><a href="../../more/index.htm">More</a></td>
|
||
</table>
|
||
<hr>
|
||
<div class="spirit-nav"><a accesskey="n" href="python/hello.html"><img src="images/next.png" alt="Next"></a></div>
|
||
<div class="chapter" lang="en">
|
||
<div class="titlepage">
|
||
<div>
|
||
<div><h2 class="title">
|
||
<a name="python"></a>Chapter 1. python 1.0</h2></div>
|
||
<div><div class="author"><h3 class="author">
|
||
<span class="firstname">Joel</span> <span class="surname">de Guzman</span>
|
||
</h3></div></div>
|
||
<div><div class="author"><h3 class="author">
|
||
<span class="firstname">David</span> <span class="surname">Abrahams</span>
|
||
</h3></div></div>
|
||
<div><p class="copyright">Copyright © 2002-2004 Joel de Guzman, David Abrahams</p></div>
|
||
<div><div class="legalnotice"><p>
|
||
Distributed under the Boost Software License, Version 1.0.
|
||
(See accompanying file LICENSE_1_0.txt or copy at
|
||
<a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">
|
||
http://www.boost.org/LICENSE_1_0.txt
|
||
</a>)
|
||
|
||
</p></div></div>
|
||
</div>
|
||
<div></div>
|
||
</div>
|
||
<div class="toc">
|
||
<p><b>Table of Contents</b></p>
|
||
<dl>
|
||
<dt><span class="section"><a href="index.html#python.quickstart">QuickStart</a></span></dt>
|
||
<dt><span class="section"><a href="python/hello.html"> Building Hello World</a></span></dt>
|
||
<dt><span class="section"><a href="python/exposing.html"> Exposing Classes</a></span></dt>
|
||
<dd><dl>
|
||
<dt><span class="section"><a href="python/exposing.html#python.constructors">Constructors</a></span></dt>
|
||
<dt><span class="section"><a href="python/exposing.html#python.class_data_members">Class Data Members</a></span></dt>
|
||
<dt><span class="section"><a href="python/exposing.html#python.class_properties">Class Properties</a></span></dt>
|
||
<dt><span class="section"><a href="python/exposing.html#python.inheritance">Inheritance</a></span></dt>
|
||
<dt><span class="section"><a href="python/exposing.html#python.class_virtual_functions">Class Virtual Functions</a></span></dt>
|
||
<dt><span class="section"><a href="python/exposing.html#python.deriving_a_python_class">Deriving a Python Class</a></span></dt>
|
||
<dt><span class="section"><a href="python/exposing.html#python.virtual_functions_with_default_implementations">Virtual Functions with Default Implementations</a></span></dt>
|
||
<dt><span class="section"><a href="python/exposing.html#python.class_operators_special_functions">Class Operators/Special Functions</a></span></dt>
|
||
</dl></dd>
|
||
<dt><span class="section"><a href="python/functions.html">Functions</a></span></dt>
|
||
<dd><dl>
|
||
<dt><span class="section"><a href="python/functions.html#python.call_policies">Call Policies</a></span></dt>
|
||
<dt><span class="section"><a href="python/functions.html#python.overloading">Overloading</a></span></dt>
|
||
<dt><span class="section"><a href="python/functions.html#python.default_arguments">Default Arguments</a></span></dt>
|
||
<dt><span class="section"><a href="python/functions.html#python.auto_overloading">Auto-Overloading</a></span></dt>
|
||
</dl></dd>
|
||
<dt><span class="section"><a href="python/object.html"> Object Interface</a></span></dt>
|
||
<dd><dl>
|
||
<dt><span class="section"><a href="python/object.html#python.basic_interface">Basic Interface</a></span></dt>
|
||
<dt><span class="section"><a href="python/object.html#python.derived_object_types">Derived Object types</a></span></dt>
|
||
<dt><span class="section"><a href="python/object.html#python.extracting_c___objects">Extracting C++ objects</a></span></dt>
|
||
<dt><span class="section"><a href="python/object.html#python.enums">Enums</a></span></dt>
|
||
</dl></dd>
|
||
<dt><span class="section"><a href="python/embedding.html">Embedding</a></span></dt>
|
||
<dd><dl><dt><span class="section"><a href="python/embedding.html#python.using_the_interpreter">Using the interpreter</a></span></dt></dl></dd>
|
||
<dt><span class="section"><a href="python/iterators.html">Iterators</a></span></dt>
|
||
<dt><span class="section"><a href="python/exception.html"> Exception Translation</a></span></dt>
|
||
<dt><span class="section"><a href="python/techniques.html"> General Techniques</a></span></dt>
|
||
<dd><dl>
|
||
<dt><span class="section"><a href="python/techniques.html#python.creating_packages">Creating Packages</a></span></dt>
|
||
<dt><span class="section"><a href="python/techniques.html#python.extending_wrapped_objects_in_python">Extending Wrapped Objects in Python</a></span></dt>
|
||
<dt><span class="section"><a href="python/techniques.html#python.reducing_compiling_time">Reducing Compiling Time</a></span></dt>
|
||
</dl></dd>
|
||
</dl>
|
||
</div>
|
||
<div class="section" lang="en">
|
||
<div class="titlepage">
|
||
<div><div><h2 class="title" style="clear: both">
|
||
<a name="python.quickstart"></a>QuickStart</h2></div></div>
|
||
<div></div>
|
||
</div>
|
||
<p>
|
||
The Boost Python Library is a framework for interfacing Python and
|
||
C++. It allows you to quickly and seamlessly expose C++ classes
|
||
functions and objects to Python, and vice-versa, using no special
|
||
tools -- just your C++ compiler. It is designed to wrap C++ interfaces
|
||
non-intrusively, so that you should not have to change the C++ code at
|
||
all in order to wrap it, making Boost.Python ideal for exposing
|
||
3rd-party libraries to Python. The library's use of advanced
|
||
metaprogramming techniques simplifies its syntax for users, so that
|
||
wrapping code takes on the look of a kind of declarative interface
|
||
definition language (IDL).</p>
|
||
<a name="quickstart.hello_world"></a><h2>
|
||
<a name="id344076"></a>Hello World</h2>
|
||
<p>
|
||
Following C/C++ tradition, let's start with the "hello, world". A C++
|
||
Function:</p>
|
||
<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">
|
||
{</span><span class="keyword">
|
||
return</span><span class="string"> "hello, world"</span><span class="special">;</span><span class="special">
|
||
}</span></tt></pre>
|
||
<p>
|
||
can be exposed to Python by writing a Boost.Python wrapper:</p>
|
||
<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">
|
||
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">
|
||
|
||
BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">hello</span><span class="special">)</span><span class="special">
|
||
{</span><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><span class="special">
|
||
}</span></tt></pre>
|
||
<p>
|
||
That's it. We're done. We can now build this as a shared library. The
|
||
resulting DLL is now visible to Python. Here's a sample Python session:</p>
|
||
<pre class="programlisting"><tt class="literal"><span class="special">>>></span><span class="identifier"> import</span><span class="identifier"> hello</span><span class="special">
|
||
>>></span><span class="identifier"> print</span><span class="identifier"> hello</span><span class="special">.</span><span class="identifier">greet</span><span class="special">()</span><span class="identifier">
|
||
hello</span><span class="special">,</span><span class="identifier"> world</span></tt></pre>
|
||
<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>
|
||
</div>
|
||
</div>
|
||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||
<td align="left"><small><p>Last revised: October 12, 2004 at 03:11:11 GMT</p></small></td>
|
||
<td align="right"><small></small></td>
|
||
</tr></table>
|
||
<hr>
|
||
<div class="spirit-nav"><a accesskey="n" href="python/hello.html"><img src="images/next.png" alt="Next"></a></div>
|
||
</body>
|
||
</html>
|