Macros | |
| #define | REPY_FN_IF_CACHE_INIT(helper_identifier) |
| Initializes the helpers for cached Pythonic if statements in the current scope. | |
| #define | REPY_FN_IF_CACHE_STMT(helper_identifier, py_expression) |
| Constructs a if statement that uses a cached Python expression executed in the current scope. | |
| #define | REPY_FN_IF_CACHE(helper_identifier, py_expression) |
| Initializes the helpers for a cached Pythonic if/else block, and constructs the first if statement, using a cached Python expression executed in the local scope. | |
| #define | REPY_FN_ELIF_CACHE(helper_identifier, py_expression) |
| Constructs a else if statement that uses a cached Python expression executed in the current scope. | |
Because code string parsing and execution requires contiguous, compilable strings, there is no good way to call back into mod code from within a if/else block within Python code. As an alternative, this section provides an easy and performant way to use the Python scope to govern mod code if/else blocks utilizing REPY_IfStmtHelper.
There are no REPY_FN_IF or REPY_FN_IF_CSTR variations of these macros, as simple REPY_FN_EVAL_BOOL and REPY_FN_EVAL_CSTR_BOOL calls could be used as the conditions of if statements directly. Nevertheless, the term CACHE is included in these macro names to indicate that purpose and behavior; As per the design of REPY_IfStmtHelper, the code strings given to these macros are only parsed once, and the bytecode stored for repeated evaluations.
| #define REPY_FN_ELIF_CACHE | ( | helper_identifier, | |
| py_expression ) |
Constructs a else if statement that uses a cached Python expression executed in the current scope.
Requires using the helpers initialized by REPY_FN_IF_CACHE_INIT or REPY_FN_IF_CACHE.
See the REPY_IfStmtHelper section for more information.
| helper_identifier | The variable name of the REPY_IfStmtHelper object. Needs to be the same as the value used when initializing this if/else block (using either REPY_FN_IF_CACHE_INIT or REPY_FN_IF_CACHE). |
| py_expression | The Python expression to evaluate within the scope. Should be a NULL-terminated C string. |
| #define REPY_FN_IF_CACHE | ( | helper_identifier, | |
| py_expression ) |
Initializes the helpers for a cached Pythonic if/else block, and constructs the first if statement, using a cached Python expression executed in the local scope.
This is the simplest way to handle Pythonic if/else blocks in C code, provided there are no additional C expressions that need to be evaluated as well.
See the REPY_IfStmtHelper section for more information.
| helper_identifier | The variable name of the REPY_IfStmtHelper object, as well as the prefix for the static REPY_IfStmtChain* object. |
| py_expression | The Python expression to evaluate within the scope. Should be a NULL-terminated C string. |
| #define REPY_FN_IF_CACHE_INIT | ( | helper_identifier | ) |
Initializes the helpers for cached Pythonic if statements in the current scope.
This macro is used as part of REPY_FN_IF_CACHE, but you can invoke it manually if needed (for example, if you're mixing Python and C if statements in one if/else block).
See the REPY_IfStmtHelper section for more information.
| helper_identifier | The variable name of the REPY_IfStmtHelper object, as well as the prefix for the static REPY_IfStmtChain* object. |
| #define REPY_FN_IF_CACHE_STMT | ( | helper_identifier, | |
| py_expression ) |
Constructs a if statement that uses a cached Python expression executed in the current scope.
This macro is used as part of REPY_FN_IF_CACHE and REPY_FN_ELIF_CACHE, but you can invoke it manually if needed (for example, if you're mixing Python and C if statements in one if/else block).
See the REPY_IfStmtHelper section for more information.
| helper_identifier | The variable name of the REPY_IfStmtHelper object. Needs to be the same as the value used when initializing this if/else block (using either REPY_FN_IF_CACHE_INIT or REPY_FN_IF_CACHE). |
| py_expression | The Python expression to evaluate within the scope. Should be a NULL-terminated C string. |