Defining Python classes from C++ with methods, properties, operators, and nested types.
This module provides the internal machinery used by the class export macros to define Python classes backed by C++ types. A class definition aggregates constructors, methods (including Python special methods/operators), properties, static members, nested classes and enums, and then materializes a Python type when frozen.
A Python class can contain:
To export a C++ class to Python, you typically use macros that work on a Python class. Macro names follow a consistent grammar, see Python Macro Name Conventions.
Topics | |
| Class Attribute Export Macros | |
| Export values and nested types as attributes on the Python class itself. | |
| Method Export Macros | |
| These macros export C++ methods on a class to Python. | |
| Casting Method Export Macros (Deprecated) | |
| Static Method Export Macros | |
| Export C++ static methods or free functions as Python static methods. | |
| Data Member Export Macros | |
| Export C++ class data members as Python properties. | |
| Constructor Export Macros | |
| Export C++ constructors directly as Python class constructors. | |
Classes | |
| class | lass::python::impl::ClassDefinition |
| Definition of a Python class. More... | |
Class Declaration & Setup | |||||||||||||||||||||
Macros to declare and configure Python classes from C++ types. These macros create the internal class definition objects that aggregate all the information needed to generate a Python type. Every C++ class that needs to be exposed to Python must be declared using one of these macros. LASS supports two approaches for exporting C++ classes to Python:
The basic form is PY_DECLARE_CLASS( i_cppClass )
#define PY_DECLARE_CLASS(i_cppClass) Declare a Python class with automatic name and no documentation. Definition pyobject_macros.h:3891 with:
The
| |||||||||||||||||||||
| #define | PY_DECLARE_CLASS_NAME_DOC(t_cppClass, s_name, s_doc) | ||||||||||||||||||||
| Declare a Python class with full control over name and documentation. | |||||||||||||||||||||
| #define | PY_DECLARE_CLASS_NAME(t_cppClass, s_name) | ||||||||||||||||||||
| Declare a Python class with custom name but no documentation. | |||||||||||||||||||||
| #define | PY_DECLARE_CLASS_DOC(i_cppClass, s_doc) | ||||||||||||||||||||
| Declare a Python class with automatic name and custom documentation. | |||||||||||||||||||||
| #define | PY_DECLARE_CLASS(i_cppClass) | ||||||||||||||||||||
| Declare a Python class with automatic name and no documentation. | |||||||||||||||||||||
| #define | PY_DECLARE_CLASS_EX(t_cppClass, s_name, i_uniqueClassIdentifier) | ||||||||||||||||||||
| Legacy class declaration macro. | |||||||||||||||||||||
| #define PY_DECLARE_CLASS_NAME_DOC | ( | t_cppClass, | |
| s_name, | |||
| s_doc ) |
Declare a Python class with full control over name and documentation.
This is the primary class declaration macro that creates the internal ClassDefinition object for a C++ class. All other class declaration macros ultimately call this one. The class definition collects constructors, methods, properties, and other elements that will be added later using PY_CLASS_* macros.
| t_cppClass | Python binding class type. This must be either:
|
| s_name | Python class name as string literal |
| s_doc | Class documentation string (or nullptr for no doc) |
Definition at line 3834 of file pyobject_macros.h.
| #define PY_DECLARE_CLASS_NAME | ( | t_cppClass, | |
| s_name ) |
Declare a Python class with custom name but no documentation.
Convenience wrapper around PY_DECLARE_CLASS_NAME_DOC that omits the documentation string. Use this when you want to control the Python class name but don't need documentation.
| t_cppClass | Python binding class type (PyObjectPlus-derived or shadow class) |
| s_name | Python class name as string literal |
Definition at line 3856 of file pyobject_macros.h.
| #define PY_DECLARE_CLASS_DOC | ( | i_cppClass, | |
| s_doc ) |
Declare a Python class with automatic name and custom documentation.
Convenience wrapper that uses the C++ class name as the Python class name but allows custom documentation. The class name is automatically stringified.
| i_cppClass | Python-exportable C++ class identifier (unqualified name) |
| s_doc | Class documentation string |
Definition at line 3874 of file pyobject_macros.h.
| #define PY_DECLARE_CLASS | ( | i_cppClass | ) |
Declare a Python class with automatic name and no documentation.
The simplest class declaration macro. Uses the C++ class name as the Python class name and provides no documentation string. Most commonly used for basic class exports.
| i_cppClass | Python binding class identifier (unqualified name) |
Definition at line 3891 of file pyobject_macros.h.
| #define PY_DECLARE_CLASS_EX | ( | t_cppClass, | |
| s_name, | |||
| i_uniqueClassIdentifier ) |
Legacy class declaration macro.
| t_cppClass | Python binding class type |
| s_name | Python class name |
| i_uniqueClassIdentifier | Unused parameter (legacy) |
Definition at line 3905 of file pyobject_macros.h.