Library of Assembled Shared Sources
|
Definition of a Python module. More...
#include <module_definition.h>
Public Types | |
typedef util::Callback0 | TPreInject |
Callback type for pre-injection hooks (called before module creation). | |
typedef util::Callback1< PyObject * > | TPostInject |
Callback type for post-injection hooks (called after module creation with module object). | |
Public Member Functions | |
ModuleDefinition (const char *name, const char *doc=0) | |
Construct module definition with name and optional documentation. | |
const char * | name () const |
Get the module name. | |
void | setName (const char *name) |
Set the module name. | |
const char * | doc () const |
Get the module documentation string. | |
void | setDoc (const char *doc) |
Set the module documentation string. | |
PyObject * | module () const |
Get the Python module object (available after inject() has been called). | |
void | setPreInject (const TPreInject &callback) |
Set callback to be executed before module injection. | |
void | setPostInject (const TPostInject &callback) |
Set callback to be executed after module injection. | |
void | addFunctionDispatcher (PyCFunction dispatcher, const char *name, const char *doc, PyCFunction &overloadChain) |
Add a function dispatcher to the module. | |
void | addClass (impl::ClassDefinition &classDef) |
Add a class definition to the module. | |
void | addEnum (EnumDefinitionBase *enumDef) |
Add an enum definition to the module. | |
void | addObject (PyObject *object, const char *name) |
Add an arbitrary Python object to the module. | |
void | addLong (long object, const char *name) |
Add a long integer constant to the module. | |
void | addString (const char *object, const char *name) |
Add a string constant to the module. | |
void | injectLong (const char *name, long value) |
Inject a long integer directly into an already created module. | |
void | injectString (const char *name, const char *value) |
Inject a string directly into an already created module. | |
template<typename T> | |
void | injectObject (T &&object, const char *name) |
Inject an arbitrary object directly into an already created module. | |
bool | injectClass (impl::ClassDefinition &classDef) |
Inject a class definition directly into an already created module. | |
PyObject * | inject () |
Create and inject the Python module with all accumulated definitions. | |
Definition of a Python module.
Holds the definition of a Python module and can create the module by calling inject(). This class manages all components that make up a Python module: functions, classes, enums, and other objects.
The module definition accumulates all components during the program initialization phase, then creates the actual Python module when inject() is called.
This class is typically not used directly by user code. Use the provided macros in pyobject_macros.h that work with ModuleDefinition instances.
Definition at line 117 of file module_definition.h.
lass::python::ModuleDefinition::ModuleDefinition | ( | const char * | name, |
const char * | doc = 0 ) |
Construct module definition with name and optional documentation.
name | Python module name (will be copied and stored internally) |
doc | Optional module docstring (will be copied and stored internally, or nullptr) |
Definition at line 73 of file module_definition.cpp.
void lass::python::ModuleDefinition::setName | ( | const char * | name | ) |
Set the module name.
name | New module name (will be copied and stored internally) |
Definition at line 113 of file module_definition.cpp.
References name().
Referenced by ModuleDefinition().
void lass::python::ModuleDefinition::setDoc | ( | const char * | doc | ) |
Set the module documentation string.
doc | New docstring (will be copied and stored internally, or nullptr) |
Definition at line 118 of file module_definition.cpp.
References doc().
Referenced by ModuleDefinition().
void lass::python::ModuleDefinition::setPreInject | ( | const TPreInject & | callback | ) |
Set callback to be executed before module injection.
callback called at start of module injection
Useful for performing setup tasks before the module is created.
callback | Function to call before injection |
Definition at line 125 of file module_definition.cpp.
void lass::python::ModuleDefinition::setPostInject | ( | const TPostInject & | callback | ) |
Set callback to be executed after module injection.
callback called at end of module injection, with module as parameter
Useful for performing additional setup on the created module.
callback | Function to call with the module object after injection |
Definition at line 132 of file module_definition.cpp.
void lass::python::ModuleDefinition::addFunctionDispatcher | ( | PyCFunction | dispatcher, |
const char * | name, | ||
const char * | doc, | ||
PyCFunction & | overloadChain ) |
Add a function dispatcher to the module.
Used internally by function export macros to register C++ functions.
dispatcher | Function dispatcher for overload resolution |
name | Python function name |
doc | Function documentation string |
overloadChain | Reference to overload chain for this function name |
Definition at line 181 of file module_definition.cpp.
void lass::python::ModuleDefinition::addClass | ( | impl::ClassDefinition & | classDef | ) |
Add a class definition to the module.
new-style class addition.
The class will be created and added when the module is injected.
classDef | Class definition containing class export information |
This function adds a class definition to a table that will be injected when the module is.
Definition at line 141 of file module_definition.cpp.
void lass::python::ModuleDefinition::addEnum | ( | EnumDefinitionBase * | enumDef | ) |
Add an enum definition to the module.
The enum type will be created and added when the module is injected.
enumDef | Enum definition containing enum export information |
Definition at line 147 of file module_definition.cpp.
void lass::python::ModuleDefinition::addObject | ( | PyObject * | object, |
const char * | name ) |
Add an arbitrary Python object to the module.
The object will be added directly to the module namespace.
object | Python object to add |
name | Name for the object in the module namespace |
Definition at line 153 of file module_definition.cpp.
References name().
void lass::python::ModuleDefinition::addLong | ( | long | object, |
const char * | name ) |
Add a long integer constant to the module.
object | Long value to add as module constant |
name | Name for the constant in the module namespace |
Definition at line 162 of file module_definition.cpp.
References name().
void lass::python::ModuleDefinition::addString | ( | const char * | object, |
const char * | name ) |
Add a string constant to the module.
object | String value to add as module constant |
name | Name for the string in the module namespace |
Definition at line 171 of file module_definition.cpp.
References name().
void lass::python::ModuleDefinition::injectLong | ( | const char * | name, |
long | value ) |
Inject a long integer directly into an already created module.
This is for immediate injection, unlike addLong() which defers until inject().
name | Name for the constant in the module namespace |
value | Long value to inject |
Definition at line 198 of file module_definition.cpp.
References name().
void lass::python::ModuleDefinition::injectString | ( | const char * | name, |
const char * | value ) |
Inject a string directly into an already created module.
This is for immediate injection, unlike addString() which defers until inject().
name | Name for the string in the module namespace |
value | String value to inject |
Definition at line 205 of file module_definition.cpp.
References name().
|
inline |
Inject an arbitrary object directly into an already created module.
This is for immediate injection, unlike addObject() which defers until inject().
object | Object to inject (will be converted to Python object) |
name | Name for the object in the module namespace |
Definition at line 222 of file module_definition.h.
References name().
bool lass::python::ModuleDefinition::injectClass | ( | impl::ClassDefinition & | classDef | ) |
Inject a class definition directly into an already created module.
old-style class injection.
classDef | Class definition to inject |
This function can injects a class in an already-injected module
Definition at line 217 of file module_definition.cpp.
References lass::python::impl::ClassDefinition::freezeDefinition(), and lass::python::impl::ClassDefinition::name().
PyObject * lass::python::ModuleDefinition::inject | ( | ) |
Create and inject the Python module with all accumulated definitions.
This method should typically not be called directly. Use module registration macros which call this at the appropriate time during Python initialization.
Definition at line 227 of file module_definition.cpp.
References lass::python::chainErrFormat().