[问题] embedding in c, 用 ctypes delegate

楼主: b26168 (b26168)   2018-01-15 16:19:56
参考了这个问题的第二个做法
成功了将 C 端的 object delegate 过来给 python
https://stackoverflow.com/questions/21988970/how-do-i-pass-an-objective-c-instance-into-a-pyobjc-python-function-when-using-p
但如果今天 delegate.aMethod 变成要传入参数的情况
一直不知道该怎么做
尝试了 delegate.aMethod.restype 跟 .argtypes 的宣告
似乎就直接 crash 掉了 (python 新手, 不太知道如何去 debug 这个错误)
不知道有没有人知道这个冷门的问题该如何解??
感谢!
附上使用范例
def myCallable(delegateID):
_objc = ctypes.PyDLL(objc._objc.__file__)
_objc.PyObjCObject_New.restype = ctypes.py_object
_objc.PyObjCObject_New.argtypes = [ctypes.c_void_p, ctypes.c_int,
ctypes.c_int]
delegate = _objc.PyObjCObject_New(delegateID, 0, 1)
delegate.aMethod.restype = ctypes.bool
delegate.aMethod.argtypes = [ctypes.c_int]
delegate.aMethod(ctypes.c_int(123))
Objective - C 的宣告
-(bool)aMethod:(int)a;
以上
作者: uranusjr (←這人是超級笨蛋)   2018-01-15 16:28:00
啊你也不给个会 crash 的范例现在是要通灵吗试试把 Python 端的 aMethod 改成 aMethod_

Links booklink

Contact Us: admin [ a t ] ucptt.com