diff --git a/doc/v2/module.html b/doc/v2/module.html index 4b3017bc..42658832 100644 --- a/doc/v2/module.html +++ b/doc/v2/module.html @@ -32,36 +32,14 @@ "#BOOST_PYTHON_MODULE-spec">BOOST_PYTHON_MODULE -
Classes - -
-
-
Class module - -
-
-
Class module - synopsis - -
Class module - constructor - -
Class module - modifier functions - -
Class module - observer functions -
-
-
Example(s)

Introduction

-

This header provides the basic facilities needed to create an - extension module. +

This header provides the basic facilities needed to create a + Boost.Python extension module.

Macros

@@ -75,157 +53,27 @@ "http://www.python.org/doc/2.2/ref/identifiers.html">identifier naming rules. Where you would normally write
-void initname()
+extern "C" void initname()
 {
    ...
+}
 
Boost.Python modules should be initialized with
 BOOST_PYTHON_MODULE(name)
 {
    ...
+}
 
-

Classes

+This macro generates two functions in the scope where it is used: +extern "C" void initname(), +and void init_module_name(), whose body must +follow the macro invocation. init_name passes +init_module_name to () so that any C++ +exceptions generated are safely processeed. -

Class module

- -

This class represents the Python extension module under construction. It - provides functions for adding attributes and for retrieving the underlying - Python module object. - -

Class module - synopsis

-
-namespace boost { namespace python
-{
-  class module : public module_base
-  {
-   public:
-      module(const char* name);
-
-      // modifier functions
-      module& setattr(const char* name, PyObject*);
-      module& setattr(const char* name, PyTypeObject*);
-      module& setattr(const char* name, ref const&);
-
-      module& add(PyTypeObject* x);
-      template <class T, class Bases, class HolderGenerator>
-      module& add(class_<T,Bases,HolderGenerator> const& c);
-
-      template <class Fn>
-      module& def(char const* name, Fn fn);
-      template <class Fn, class ResultHandler>
-      module& def(char const* name, Fn fn, ResultHandler handler);
-
-      // observer function
-      ref object() const;
-  };
-
-}}
-
- -

Class module - constructor

-
-module(const char* name);
-
- -
-
Requires: name is a ntbs whose value matches the - argument passed to BOOST_PYTHON_MODULE. - -
Effects: Creates a module object representing a - Python module named name. -
- -

Class module modifier - functions

-
-module& setattr(const char* name, PyObject* obj);
-module& setattr(const char* name, PyTypeObject* obj);
-module& setattr(const char* name, ref const& r);
-
- -
-
Requires: name is a ntbs which conforms to - Python's identifier - naming rules. In the first two forms, obj is non-null. - In the third form, r.get() is non-null. - -
Effects: Adds the given Python object to the module. If the - object is a product of make_function(), the - usual overloading procedure applies. - In the first two forms, ownership of a reference to obj is transferred - from caller to callee, even if an exception is thrown. - -
Returns: *this -
-
-module& add(PyTypeObject* x);
-
-template <class T, class Bases, class HolderGenerator>
-module& add(class_<T,Bases,HolderGenerator> const& c);
-
- -
-
Requires: In the first form, x is non-null - -
Effects: The first form adds the Python type object named by - x to the Python module under construction, with the name - given by the type's tp_name - field. The second form adds the extension class object being constructed - by c to the module, with the same name that was passed to - c's constructor. - -
Returns: *this - -
Rationale: Provides a way to set type attributes in the module - without having to explicitly specify the name. -
-
-template <class Fn>
-module& def(char const* name, Fn f);
-
-template <class Fn, class ResultHandler>
-module& def(char const* name, Fn f, ResultHandler handler);
-
- -
- -
Requires: f is a non-null pointer-to-function or - pointer-to-member-function. name is a ntbs which conforms to - Python's identifier - naming rules. In the first form, the return type of - f is not a reference and is not a pointer other - than char const* or PyObject*. In the - second form policy is a model of CallPolicy. - -
Effects: Adds the result of make_function(f) to - the extension module being defined, with the given name. If - the module already has an attribute named name, the - usual overloading procedure applies. - -
Returns: *this -
- -

Class module observer - functions

-
-ref object() const;
-
- -
-
Returns: A ref object which holds a reference to - the Python module object created by the module constructor. -

Example(s)

@@ -233,28 +81,23 @@ ref object() const;
 #include <boost/python/module.hpp>
 
-char const* greet()
+BOOST_PYTHON_MODULE(xxx)
 {
-    return "hello, Boost.Python!";
-}
-
-BOOST_PYTHON_MODULE(boost_greet)
-{
-    module("boost_greet")
-        .def("greet", greet);
+    throw "something bad happened"
 }
 
Interactive Python:
->>> import boost_greet
->>> boost_greet.greet()
-'hello, Boost.Python!'
+>>> import xxx
+Traceback (most recent call last):
+  File "", line 1, in ?
+RuntimeError: Unidentifiable C++ Exception
 

Revised - 14 February, 2002 + 2 October, 2002