15 #include "pythonCallbackObject.h"
21 #include "callbackData.h"
22 #include "config_util.h"
26 Configure(config_pythonCallbackObject);
27 ConfigureFn(config_pythonCallbackObject) {
28 PythonCallbackObject::init_type();
32 extern struct Dtool_PyTypedObject Dtool_TypedObject;
40 PythonCallbackObject::
41 PythonCallbackObject(PyObject *
function) {
45 set_function(
function);
47 #ifndef SIMPLE_THREADS
50 #ifdef WITH_THREAD // This symbol defined within Python.h
52 #if PY_VERSION_HEX >= 0x03020000
66 PythonCallbackObject::
67 ~PythonCallbackObject() {
78 void PythonCallbackObject::
79 set_function(PyObject *
function) {
83 if (_function != Py_None && !PyCallable_Check(_function)) {
84 nassert_raise(
"Invalid function passed to PythonCallbackObject");
93 PyObject *PythonCallbackObject::
107 void PythonCallbackObject::
109 #if defined(HAVE_THREADS) && !defined(SIMPLE_THREADS)
111 PyGILState_STATE gstate;
112 gstate = PyGILState_Ensure();
115 do_python_callback(cbdata);
117 #if defined(HAVE_THREADS) && !defined(SIMPLE_THREADS)
118 PyGILState_Release(gstate);
129 void PythonCallbackObject::
131 nassertv(cbdata != NULL);
136 DTool_CreatePyInstanceTyped(cbdata, Dtool_TypedObject,
138 PyObject *args = Py_BuildValue(
"(O)", pycbdata);
145 if (result == (PyObject *)NULL) {
147 <<
"Exception occurred in " << *
this <<
"\n";
153 #endif // HAVE_PYTHON
This is a generic data block that is passed along to a CallbackObject when a callback is made...
int get_type_index() const
Returns the internal index number associated with this object's TypeHandle, a unique number for each ...
static Thread * get_current_thread()
Returns a pointer to the currently-executing Thread object.
TypeHandle is the identifier used to differentiate C++ class types.