CFFI 将回调作为参数传递给另一个函数
这是我的误解的解释:
我有一个名为 Codex 的类:
class Codex:
ffi = FFI()
def __init__(self):
self.ffi = FFI()
self.ClibDec = self.ffi.dlopen("...")
self.ffi.cdef("""int CRD_Set(int handle, int property, void *value);
int CRD_Get(int handle, int property, void *value);
""")
def funct1(self):
handle = self.ClibDec."something"
self.ClibDec.CRD_Set(handle, 0, funct2)
@ffi.callback("int(*)(int, int)")
def funct2(self, handle):
status = 0
self.ClibDec.CRD_Get(handle, 420, status)
# do something
return 0
我的问题是如何在 funct1 的 self.ClibDec.CRD_Set 内部调用 funct2 ?
我检查了几个类似的问题和文档: https://cffi.readthedocs.io/en/latest/ using.html#callbacks-old-style
但我还是不明白callback的用法(旧风格)
Here is an explanation of my misunderstanding:
I have a class named Codex:
class Codex:
ffi = FFI()
def __init__(self):
self.ffi = FFI()
self.ClibDec = self.ffi.dlopen("...")
self.ffi.cdef("""int CRD_Set(int handle, int property, void *value);
int CRD_Get(int handle, int property, void *value);
""")
def funct1(self):
handle = self.ClibDec."something"
self.ClibDec.CRD_Set(handle, 0, funct2)
@ffi.callback("int(*)(int, int)")
def funct2(self, handle):
status = 0
self.ClibDec.CRD_Get(handle, 420, status)
# do something
return 0
My question is how can I call funct2 inside self.ClibDec.CRD_Set
in my funct1 ?
I check several similar issues and the doc:
https://cffi.readthedocs.io/en/latest/using.html#callbacks-old-style
But I still not understand the usage of callback (old style)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许您正在寻找这样的代码?这将是最接近您要编写的解决方案。
Maybe you are looking for code like this? This would be the solution closest to what you're trying to write.