2 #ifndef PYINTERP_INTERP_H
3 #define PYINTERP_INTERP_H
5 #include "PyInterp.h" // !!! WARNING !!! THIS INCLUDE MUST BE THE VERY FIRST !!!
10 class PYINTERP_EXPORT PyLockWrapper
12 PyThreadState* myThreadState;
13 PyThreadState* mySaveThreadState;
14 PyGILState_STATE _savestate;
16 PyLockWrapper(PyThreadState* theThreadState);
20 typedef void PyOutChanged(void* data,char * c);
22 class PYINTERP_EXPORT PyInterp_Interp
27 static PyObject *builtinmodule;
28 static PyThreadState *_gtstate;
29 static PyInterpreterState *_interp;
32 virtual ~PyInterp_Interp();
36 virtual int run(const char *command);
38 PyLockWrapper GetLockWrapper();
40 std::string getbanner();
41 void setverrcb(PyOutChanged*,void*);
42 void setvoutcb(PyOutChanged*,void*);
44 const char * getPrevious();
45 const char * getNext();
48 PyThreadState * _tstate;
53 std::list<std::string> _history;
54 std::list<std::string>::iterator _ith;
56 virtual int beforeRun() { return 0; }
57 int simpleRun(const char* command, const bool addToHistory = true);
59 virtual bool initRun();
60 virtual void initPython();
61 virtual bool initState() = 0;
62 virtual bool initContext() = 0;
65 class PYINTERP_EXPORT PyObjWrapper
69 PyObjWrapper(PyObject* theObject) : myObject(theObject) {}
70 PyObjWrapper() : myObject(0) {}
71 virtual ~PyObjWrapper() { Py_XDECREF(myObject); }
73 operator PyObject*() { return myObject; }
74 PyObject* operator->() { return myObject; }
75 PyObject* get() { return myObject; }
76 bool operator!() { return !myObject; }
77 bool operator==(PyObject* theObject) { return myObject == theObject; }
78 PyObject** operator&() { return &myObject; }
79 PyObjWrapper& operator=(PyObjWrapper* theObjWrapper)
82 myObject = theObjWrapper->myObject;
95 #endif // PYINTERP_INTERP_H