我想在 cython 中包装以下代码:
enum Status {GOOD, BAD};
typedef enum Status STATUS;
// note that the typedef means people dont
// have to write `enum Status` everywhere
// just returns `GOOD`
STATUS hello();
Run Code Online (Sandbox Code Playgroud)
我在中编写了以下 cython 代码c_library.pxd:
cdef extern from "library.h":
cpdef enum Status:
GOOD,
BAD
ctypedef Status STATUS
cpdef STATUS hello()
Run Code Online (Sandbox Code Playgroud)
该模块c_library现在包含c_library.GOOD, c_library.BAD, and c_library.Status,其行为类似于enum。但是,函数调用的返回值hello返回一个普通的 int:
>>> c_library.hello()
0
>>> type(c_library.hello())
<class 'int'>
Run Code Online (Sandbox Code Playgroud)
我也希望将结果包装在相同类型的枚举中。我可以更改 cython 文件,但不能更改底层 C 代码。那可能吗?