![]() |
Shamrock 2025.10.0
Astrophysical Code
|
Pybind11 include and definitions. More...
#include "shambase/call_lambda.hpp"#include "shambase/unique_name_macro.hpp"#include <pybind11/pybind11.h>Go to the source code of this file.
Macros | |
| #define | _internal_register_pybind_init(funcname, lambda_name, varname) |
| Internal helper that creates static symbols to register a Python init function via a static initializer. It declares funcname, creates a call_lambda object that calls register_pybind_init_func(funcname) at startup, and defines funcname. | |
| #define | ON_PYTHON_INIT |
| Register a Python module init function using static initialization. | |
Typedefs | |
| using | fct_sig = std::function<void(py::module &)> |
| alias to pybind11 namespace | |
Functions | |
| void | register_pybind_init_func (fct_sig) |
| Register a python module init function to be ran on init. | |
Pybind11 include and definitions.
If we build shamrock executable we embed python in Shamrock hence the include pybind11/embed.h. If we build shamrock as python lib we import pybind11/pybind11.h. Both options defines a similar syntax for the python module definition, we can then wrap them conveniently in a single macro call.
Definition in file pybindaliases.hpp.
| #define _internal_register_pybind_init | ( | funcname, | |
| lambda_name, | |||
| varname ) |
Internal helper that creates static symbols to register a Python init function via a static initializer. It declares funcname, creates a call_lambda object that calls register_pybind_init_func(funcname) at startup, and defines funcname.
Here the objects/func are static in order to avoid conflicting name in linking. This is similar to anonymous namespaces
Definition at line 45 of file pybindaliases.hpp.
| #define ON_PYTHON_INIT |
Register a Python module init function using static initialization.
Generates unique symbols automatically, making it convenient for one-shot initializations in .cpp files.
Usage (in a .cpp file) :
Definition at line 69 of file pybindaliases.hpp.
| using fct_sig = std::function<void(py::module &)> |
alias to pybind11 namespace
function signature used to register python modules
Definition at line 32 of file pybindaliases.hpp.
| void register_pybind_init_func | ( | fct_sig | fct | ) |
Register a python module init function to be ran on init.
Register a python module init function to be ran on init.
Definition at line 59 of file pybindings.cpp.