I have enum that used for communication between python server and c client.
I want to have the enum just in single file, prefer to use python enum class.
Also I prefer to avoid mixing with runtime parsing of C enum in python.
I have enum that used for communication between python server and c client.
I want to have the enum just in single file, prefer to use python enum class.
Also I prefer to avoid mixing with runtime parsing of C enum in python.
Optional solution is to have the enum in *.py file, which C file can include and python can import.
The file will look like:
#if 0
"""
#endif
typedef enum my_enum{
#if 0
"""
from enum import IntEnum, unique
@unique
class MyEnum(IntEnum):
#endif
FIRST = 0,
SECOND = 1,
THIRD = 2,
#if 0
"""
#endif
}my_enum_e;
#if 0
"""
#endif
The idea behind it is that Python ignores all the C preprocessor commands, as they are in Python triple-quoted strings, which is where I put the C only code.
In the other hand, C ignores everything inside #if 0 - where I put the python code.
The disadvantage in this structure is it bit confusing and I didn't find way to make the numbering automatic.