2 #ifndef PYINTERP_INTERP_H
3 #define PYINTERP_INTERP_H
5 #include "PyInterp.h" // !!! WARNING !!! THIS INCLUDE MUST BE THE VERY FIRST !!!
13 PyThreadState* myThreadState;
14 PyThreadState* mySaveThreadState;
15 PyGILState_STATE _savestate;
17 PyLockWrapper(PyThreadState* theThreadState);
21 typedef void PyOutChanged(void* data,char * c);
29 static PyObject *builtinmodule;
30 static PyThreadState *_gtstate;
31 static PyInterpreterState *_interp;
34 virtual ~PyInterp_Interp();
38 virtual int run(const char *command);
40 PyLockWrapper GetLockWrapper();
42 std::string getbanner();
43 void setverrcb(PyOutChanged*,void*);
44 void setvoutcb(PyOutChanged*,void*);
46 const char * getPrevious();
47 const char * getNext();
50 PyThreadState * _tstate;
55 std::list<std::string> _history;
56 std::list<std::string>::iterator _ith;
58 virtual int beforeRun() { return 0; }
59 int simpleRun(const char* command, const bool addToHistory = true);
61 virtual bool initRun();
62 virtual void initPython();
63 virtual bool initState() = 0;
64 virtual bool initContext() = 0;
72 PyObjWrapper(PyObject* theObject) : myObject(theObject) {}
73 PyObjWrapper() : myObject(0) {}
74 virtual ~PyObjWrapper() { Py_XDECREF(myObject); }
76 operator PyObject*() { return myObject; }
77 PyObject* operator->() { return myObject; }
78 PyObject* get() { return myObject; }
79 bool operator!() { return !myObject; }
80 bool operator==(PyObject* theObject) { return myObject == theObject; }
81 PyObject** operator&() { return &myObject; }
82 PyObjWrapper& operator=(PyObjWrapper* theObjWrapper)
85 myObject = theObjWrapper->myObject;
98 #endif // PYINTERP_INTERP_H