Je suis en train de concevoir un bot pour une application appelée Virtual Paradise et le SDK qui est donné pour construire le bot est compilé dans une bibliothèque partagée, donc je dois utiliser ctypes.Python Ctypes comportement bizarre
quand j'utilise
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 est appelé correctement et imprime "Bonjour"
mais quand j'utilise cette
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"
...
Je reçois le er ror "Instruction illégale"
Qu'est-ce que je fais de mal? Je dois utiliser cette classe séparée, sinon les autres parties de mon bot perdront des fonctionnalités.
Merci, je viens de rendre la variable "event_chat_func" globale dans "chat.py" et maintenant cela fonctionne sans aucun problème. – MetaDark