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 -
module
-
- module
- synopsis
-
- module
- constructor
-
- module
- modifier functions
-
- module
- observer functions
- 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.
-void initname()
+extern "C" void initname()
{
...
+}
Boost.Python modules should be initialized with
BOOST_PYTHON_MODULE(name)
{
...
+}
- 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.
- moduleThis class represents the Python extension module under construction. It - provides functions for adding attributes and for retrieving the underlying - Python module object. - -
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;
- };
-
-}}
-
-
- module
- constructor-module(const char* name); -- -
name is a ntbs whose value matches the
- argument passed to BOOST_PYTHON_MODULE.
-
- module object representing a
- Python module named name.
- 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); -- -
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.
-
- 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.
-
- *this
- -module& add(PyTypeObject* x); - -template <class T, class Bases, class HolderGenerator> -module& add(class_<T,Bases,HolderGenerator> const& c); -- -
x is non-null
-
- 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.
-
- *this
-
- -template <class Fn> -module& def(char const* name, Fn f); - -template <class Fn, class ResultHandler> -module& def(char const* name, Fn f, ResultHandler handler); -- -
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.
-
- 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.
-
- *this
- module observer
- functions-ref object() const; -- -
ref object which holds a reference to
- the Python module object created by the module constructor.
-
#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