Note that there are some explanatory texts on larger screens.

plurals
  1. POPython Ctypes weird behavior
    primarykey
    data
    text
    <p>I am trying to design a bot for an application called Virtual Paradise and the SDK that is given for building the bot is compiled into a shared library, therefore I have to use ctypes.</p> <p>when I use</p> <pre><code>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" ... </code></pre> <p>event_chat gets called correctly and prints "Hello"</p> <p>but when I use this</p> <pre><code>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) ... </code></pre> <p>Chat.py:</p> <pre><code>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" ... </code></pre> <p>I get the error "Illegal instruction"</p> <p>What am I doing wrong!? I need to use this separate class, otherwise other parts of my bot will loose functionality.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload