[問題] 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