mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-25 06:35:12 +00:00
doc updates
This commit is contained in:
parent
de623a7668
commit
4a48afb356
@ -1,11 +1,26 @@
|
||||
Build systems
|
||||
#############
|
||||
|
||||
Building with setuptools
|
||||
========================
|
||||
|
||||
For projects on PyPI, building with setuptools is the way to go. Sylvain Corlay
|
||||
has kindly provided an example project which shows how to set up everything,
|
||||
including automatic generation of documentation using Sphinx. Please refer to
|
||||
the [pbtest]_ repository.
|
||||
|
||||
.. [pbtest] https://github.com/pybind/pbtest
|
||||
|
||||
.. _cmake:
|
||||
|
||||
Building with CMake
|
||||
===================
|
||||
|
||||
The following snippet should be a good starting point to create bindings across
|
||||
platforms. It assumes that the code is located in a file named :file:`example.cpp`,
|
||||
and that the pybind11 repository is located in a subdirectory named :file:`pybind11`.
|
||||
For C++ codebases that already have an existing CMake-based build system, the
|
||||
following snippet should be a good starting point to create bindings across
|
||||
platforms. It assumes that the code is located in a file named
|
||||
:file:`example.cpp`, and that the pybind11 repository is located in a
|
||||
subdirectory named :file:`pybind11`.
|
||||
|
||||
.. code-block:: cmake
|
||||
|
||||
|
24
docs/faq.rst
24
docs/faq.rst
@ -30,8 +30,24 @@ provided by the caller -- in fact, it does nothing at all.
|
||||
def increment(i):
|
||||
i += 1 # nope..
|
||||
|
||||
pybind11 is also affected by such language-level conventions, which means
|
||||
that binding ``increment`` or ``increment_ptr`` will also create Python functions that don't modify their arguments.
|
||||
pybind11 is also affected by such language-level conventions, which means that
|
||||
binding ``increment`` or ``increment_ptr`` will also create Python functions
|
||||
that don't modify their arguments.
|
||||
|
||||
Although inconvenient, one workaround is to encapsulate the immutable types in
|
||||
a custom type that does allow modifications.
|
||||
|
||||
An other alternative involves binding a small wrapper lambda function that
|
||||
returns a tuple with all output arguments (see the remainder of the
|
||||
documentation for examples on binding lambda functions). An example:
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
int foo(int &i) { i++; return 123; }
|
||||
|
||||
and the binding code
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
m.def("foo", [](int i) { int rv = foo(i); return std::make_tuple(rv, i); });
|
||||
|
||||
Although inconvenient, one workaround is to encapsulate the immutable types
|
||||
in a custom type that does allow modifications.
|
||||
|
Loading…
Reference in New Issue
Block a user