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
de3ad078
Commit
de3ad078
authored
Feb 02, 2016
by
Wenzel Jakob
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
documentation on exporting constants (closes #92)
parent
298183fa
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
1 deletions
+17
-1
docs/advanced.rst
+17
-1
No files found.
docs/advanced.rst
View file @
de3ad078
...
@@ -12,6 +12,22 @@ present:
...
@@ -12,6 +12,22 @@ present:
namespace py = pybind11;
namespace py = pybind11;
Exporting constants and mutable objects
=======================================
To expose a C++ constant, use the ``attr`` function to register it in a module
as shown below. The ``int_`` class is one of many small wrapper objects defined
in ``pybind11/pytypes.h``. General objects (including integers) can also be
converted using the function ``cast``.
.. code-block:: cpp
PYBIND11_PLUGIN(example) {
py::module m("example", "pybind11 example plugin");
m.attr("MY_CONSTANT") = py::int_(123);
m.attr("MY_CONSTANT_2") = py::cast(new MyObject());
}
Operator overloading
Operator overloading
====================
====================
...
@@ -280,7 +296,7 @@ Following this, we are able to define a constructor as usual.
...
@@ -280,7 +296,7 @@ Following this, we are able to define a constructor as usual.
The Python session below shows how to override ``Animal::go`` and invoke it via
The Python session below shows how to override ``Animal::go`` and invoke it via
a virtual method call.
a virtual method call.
.. code-block::
cpp
.. code-block::
python
>>> from example import *
>>> from example import *
>>> d = Dog()
>>> d = Dog()
...
...
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