[問題] embedding in c, 用 ctypes delegate
參考了這個問題的第二個做法
成功了將 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;
以上
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 220.128.199.139
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1516004399.A.5D1.html
→
01/15 16:28,
8年前
, 1F
01/15 16:28, 1F
crash 在 Objective-C 端, 所以就省略掉了
EXC_BAD_ACCESS
有在 python 端加上 try catch
AttributeError
※ 編輯: b26168 (220.128.199.139), 01/15/2018 16:59:48
→
01/15 20:53,
8年前
, 2F
01/15 20:53, 2F
沒有作用
原本沒有帶參數的 aMethod 是可以跑的
現在在思考 似乎不是 ctypes 的問題
而是 PyObjcObject 這個東西所取得的物件
他的 function 要怎麼帶參數給他
※ 編輯: b26168 (220.128.199.139), 01/16/2018 09:48:26
→
01/16 11:50,
8年前
, 3F
01/16 11:50, 3F
→
01/16 11:50,
8年前
, 4F
01/16 11:50, 4F
→
01/16 11:51,
8年前
, 5F
01/16 11:51, 5F
→
01/16 11:51,
8年前
, 6F
01/16 11:51, 6F