나는 Virtual Paradise라는 응용 프로그램을위한 봇을 설계하려고하는데, 봇을 빌드하기 위해 주어진 SDK가 공유 라이브러리로 컴파일되므로 ctypes를 사용해야합니다. 내가Python Ctypes weird behavior
import threading
...
from ctypes import CDLL, CFUNCTYPE, c_char_p, c_int, c_void_p
vp = CDLL("libvpsdk.so")
vp.vp_string.restype = c_char_p
vp.vp_int.restype = c_int
...
class bot(threading.Thread):
def initBot(self):
...
instance = vp.vp_create()
...
EventFunc = CFUNCTYPE(None)
event_chat_func = EventFunc(self.event_chat)
vp.vp_event_set(instance, 0, event_chat_func)
...
def event_chat(self):
print "Hello"
...
event_chat를 사용
는 및 인쇄 "안녕하세요"
제대로 호출하지만 도착 나는이
import threading
import chat
...
from ctypes import CDLL, CFUNCTYPE, c_char_p, c_int, c_void_p
vp = CDLL("libvpsdk.so")
vp.vp_string.restype = c_char_p
vp.vp_int.restype = c_int
...
class bot(threading.Thread):
def initBot(self):
...
instance = vp.vp_create()
...
chat.VPSDK(vp, instance)
...
Chat.py 사용할 때 :
from ctypes import CFUNCTYPE
...
class VPSDK:
def __init__(self, vp, instance):
EventFunc = CFUNCTYPE(None)
event_chat_func = EventFunc(self.event_chat)
vp.vp_event_set(instance, 0, event_chat_func)
def event_chat(self):
print "Hello"
...
나도 알아. ror "잘못된 명령"
내가 뭘 잘못하고있다!? 이 별도의 클래스를 사용해야합니다, 그렇지 않으면 내 봇의 다른 부분이 느슨한 기능을합니다.
감사합니다. 방금 "event_chat_func"변수를 "chat.py"내에서 전역 변수로 만들었으며 이제는 문제없이 작동합니다. – MetaDark