Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pybind11
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
pybind11
Commits
2dfbadee
Commit
2dfbadee
authored
Jan 17, 2016
by
Wenzel Jakob
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
documentation on using multiple extension modules
parent
4c1a6be4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
0 deletions
+35
-0
docs/advanced.rst
+33
-0
docs/classes.rst
+2
-0
No files found.
docs/advanced.rst
View file @
2dfbadee
...
@@ -865,3 +865,36 @@ default argument manually using the ``arg_t`` notation:
...
@@ -865,3 +865,36 @@ default argument manually using the ``arg_t`` notation:
py::class_<MyClass>("MyClass")
py::class_<MyClass>("MyClass")
.def("myFunction", py::arg_t<SomeType>("arg", SomeType(123), "SomeType(123)"));
.def("myFunction", py::arg_t<SomeType>("arg", SomeType(123), "SomeType(123)"));
Partitioning code over multiple extension modules
=================================================
It's straightforward to split binding code over multiple extension modules and
reference types declared elsewhere. Everything "just" works without any special
precautions. One exception to this rule occurs when wanting to extend a type declared
in another extension module. Recall the basic example from Section
:ref:`inheritance`.
.. code-block:: cpp
py::class_<Pet> pet(m, "Pet");
pet.def(py::init<const std::string &>())
.def_readwrite("name", &Pet::name);
py::class_<Dog>(m, "Dog", pet /* <- specify parent */)
.def(py::init<const std::string &>())
.def("bark", &Dog::bark);
Suppose now that ``Pet`` bindings are defined in a module named ``basic``,
whereas the ``Dog`` bindings are defined somewhere else. The challenge is of
course that the variable ``pet`` is not available anymore though it is needed
to indicate the inheritance relationship to the constructor of ``class_<Dog>``.
However, it can be acquired as follows:
.. code-block:: cpp
py::object pet = (py::object) py::module::import("basic").attr("Pet");
py::class_<Dog>(m, "Dog", pet)
.def(py::init<const std::string &>())
.def("bark", &Dog::bark);
docs/classes.rst
View file @
2dfbadee
...
@@ -157,6 +157,8 @@ the setter and getter functions:
...
@@ -157,6 +157,8 @@ the setter and getter functions:
and :func:`class_::def_property_readonly_static` are provided for binding
and :func:`class_::def_property_readonly_static` are provided for binding
static variables and properties.
static variables and properties.
.. _inheritance:
Inheritance
Inheritance
===========
===========
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment