Library of Assembled Shared Sources
 
Loading...
Searching...
No Matches
Module Constants and Objects Macros

Detailed Description

These macros add constants, variables, and arbitrary Python objects to modules.

They provide different approaches for exposing C++ values and objects to Python.

Macros

#define PY_MODULE_INTEGER_CONSTANT(i_module, s_name, s_value)
 Add an integer constant to a Python module.
 
#define PY_MODULE_STRING_CONSTANT(i_module, s_name, s_value)
 Add a string constant to a Python module.
 
#define PY_INJECT_OBJECT_IN_MODULE_EX(o_object, i_module, s_objectName)
 Inject an arbitrary object into an already created module at runtime.
 
#define PY_INJECT_OBJECT_IN_MODULE(o_object, i_module)
 Inject an object using its C++ identifier as the Python name.
 
#define PY_MODULE_ADD_INTEGER_CONSTANT(i_module, s_name, v_value)
 Inject an integer constant into an already created module at runtime.
 
#define PY_MODULE_ADD_STRING_CONSTANT(i_module, s_name, s_value)
 Inject a string constant into an already created module at runtime.
 

Macro Definition Documentation

◆ PY_MODULE_INTEGER_CONSTANT

#define PY_MODULE_INTEGER_CONSTANT ( i_module,
s_name,
s_value )
Value:
LASS_EXECUTE_BEFORE_MAIN_EX\
( LASS_CONCATENATE( lassExecutePyModuleIntegerConstant_, i_module),\
i_module.addLong( s_value, s_name); )

Add an integer constant to a Python module.

The constant will be added to the module during module creation (at injection time). This is executed before main(), so the constant is available when the module is created.

Parameters
i_moduleModule identifier declared by PY_DECLARE_MODULE_*
s_namePython name of constant (const char* string with static storage duration)
s_valueInteger value of the constant (long)
Example
PY_MODULE_INTEGER_CONSTANT(mymodule, "ANSWER", 42) // mymodule.ANSWER == 42
#define PY_MODULE_INTEGER_CONSTANT(i_module, s_name, s_value)
Add an integer constant to a Python module.

Definition at line 431 of file pyobject_macros.h.

◆ PY_MODULE_STRING_CONSTANT

#define PY_MODULE_STRING_CONSTANT ( i_module,
s_name,
s_value )
Value:
LASS_EXECUTE_BEFORE_MAIN_EX\
( LASS_CONCATENATE( lassExecutePyModuleIntegerConstant_, i_module),\
i_module.addString( s_value, s_name); )

Add a string constant to a Python module.

The constant will be added to the module during module creation (at injection time). This is executed before main(), so the constant is available when the module is created.

Parameters
i_moduleModule identifier declared by PY_DECLARE_MODULE_*
s_namePython name of constant (const char* string with static storage duration)
s_valueString value of the constant (const char* string with static storage duration)
Example
PY_MODULE_STRING_CONSTANT(mymodule, "GREETING", "hello") // mymodule.GREETING == "hello"
#define PY_MODULE_STRING_CONSTANT(i_module, s_name, s_value)
Add a string constant to a Python module.

Definition at line 453 of file pyobject_macros.h.

◆ PY_INJECT_OBJECT_IN_MODULE_EX

#define PY_INJECT_OBJECT_IN_MODULE_EX ( o_object,
i_module,
s_objectName )
Value:
{\
i_module.injectObject( o_object, s_objectName );\
}

Inject an arbitrary object into an already created module at runtime.

This performs immediate injection into the module namespace, unlike the PY_MODULE_*_CONSTANT macros which defer injection until module creation.

Must be called after the module has been injected with PY_INJECT_MODULE.

Parameters
o_objectObject/variable to be injected (will be converted to Python object)
i_moduleModule identifier of an already injected module
s_objectNamePython name of object (const char* string with static storage duration)
Note
This macro must be invoked after the module has been created. It's best to place this in a postInject function as shown in the example below. The postInject function gets the module object as a parameter, but don't use that if you want the Lass stubgen tool to work correctly. Work on the module definition instead (the one you created with PY_DECLARE_MODULE()).
Example
PY_DECLARE_MODULE( mymodule )
void mymodule_postinject(PyObject*)
{
PY_INJECT_OBJECT_IN_MODULE_EX(spam, mymodule, "SPAM") // mymodule.SPAM
}
LASS_EXECUTE_BEFORE_MAIN( mymodule.setPostInject(mymodule_postinject); )
#define PY_INJECT_OBJECT_IN_MODULE_EX(o_object, i_module, s_objectName)
Inject an arbitrary object into an already created module at runtime.
#define PY_DECLARE_MODULE(i_module)
Declare a module with minimal setup (name derived from identifier, no documentation).
#define PY_MODULE_ENTRYPOINT(i_module)
Create a Python module initialization function using the module identifier as the name.

Definition at line 489 of file pyobject_macros.h.

◆ PY_INJECT_OBJECT_IN_MODULE

#define PY_INJECT_OBJECT_IN_MODULE ( o_object,
i_module )
Value:
PY_INJECT_OBJECT_IN_MODULE_EX(o_object, i_module, LASS_STRINGIFY(o_object))

Inject an object using its C++ identifier as the Python name.

Wraps PY_INJECT_OBJECT_IN_MODULE_EX() with s_objectName derived from o_object.

Parameters
o_objectObject/variable to be injected (name will be used as Python name)
i_moduleModule identifier of an already injected module
Note
This macro must be invoked after the module has been created. It's best to place this in a postInject function as shown in the example below. The postInject function gets the module object as a parameter, but don't use that if you want the Lass stubgen tool to work correctly. Work on the module definition instead (the one you created with PY_DECLARE_MODULE()).
Example
PY_DECLARE_MODULE( mymodule )
void mymodule_postinject(PyObject*)
{
PY_INJECT_OBJECT_IN_MODULE(spam, mymodule) // mymodule.spam
}
LASS_EXECUTE_BEFORE_MAIN( mymodule.setPostInject(mymodule_postinject); )
#define PY_INJECT_OBJECT_IN_MODULE(o_object, i_module)
Inject an object using its C++ identifier as the Python name.

Definition at line 519 of file pyobject_macros.h.

◆ PY_MODULE_ADD_INTEGER_CONSTANT

#define PY_MODULE_ADD_INTEGER_CONSTANT ( i_module,
s_name,
v_value )
Value:
{\
i_module.injectLong(s_name, v_value);\
}

Inject an integer constant into an already created module at runtime.

This performs immediate injection, unlike PY_MODULE_INTEGER_CONSTANT which registers the constant for inclusion during module creation.

Parameters
i_moduleModule identifier of an already injected module
s_namePython name of constant (const char* string with static storage duration)
v_valueInteger value of the constant (long)
Note
This macro must be invoked after the module has been created. It's best to place this in a postInject function as shown in the example below. The postInject function gets the module object as a parameter, but don't use that if you want the Lass stubgen tool to work correctly. Work on the module definition instead (the one you created with PY_DECLARE_MODULE()).
Example
PY_DECLARE_MODULE( mymodule )
void mymodule_postinject(PyObject*)
{
PY_MODULE_ADD_INTEGER_CONSTANT(mymodule, "ANSWER", 42) // mymodule.ANSWER == 42
}
LASS_EXECUTE_BEFORE_MAIN( mymodule.setPostInject(mymodule_postinject); )
#define PY_MODULE_ADD_INTEGER_CONSTANT(i_module, s_name, v_value)
Inject an integer constant into an already created module at runtime.

Definition at line 551 of file pyobject_macros.h.

◆ PY_MODULE_ADD_STRING_CONSTANT

#define PY_MODULE_ADD_STRING_CONSTANT ( i_module,
s_name,
s_value )
Value:
{\
i_module.injectString(s_name, s_value);\
}

Inject a string constant into an already created module at runtime.

This performs immediate injection, unlike PY_MODULE_STRING_CONSTANT which registers the constant for inclusion during module creation.

Parameters
i_moduleModule identifier of an already injected module
s_namePython name of constant (const char* string with static storage duration)
s_valueString value of the constant (const char* string with static storage duration)
Note
This macro must be invoked after the module has been created. It's best to place this in a postInject function as shown in the example below. The postInject function gets the module object as a parameter, but don't use that if you want the Lass stubgen tool to work correctly. Work on the module definition instead (the one you created with PY_DECLARE_MODULE()).
Example
PY_DECLARE_MODULE( mymodule )
void mymodule_postinject(PyObject*)
{
PY_MODULE_ADD_STRING_CONSTANT(mymodule, "GREETING", "hello") // mymodule.GREETING == "hello"
}
LASS_EXECUTE_BEFORE_MAIN( mymodule.setPostInject(mymodule_postinject); )
#define PY_MODULE_ADD_STRING_CONSTANT(i_module, s_name, s_value)
Inject a string constant into an already created module at runtime.

Definition at line 585 of file pyobject_macros.h.