34 PyObject *python::module;
37 PyObject *get_py_obj (
void *instance,
const char* class_name);
68 sprintf ( buf,
"import sys ; sys.path.insert(0, \"%s\")", name );
69 PyRun_SimpleString ( buf );
81 PyRun_SimpleString(s);
93 cerr <<
"exec_file: " << filename <<
" load failed: " << endl;
109 if ( PyErr_Occurred() )
119 PyObject *result = PyImport_ImportModule ((
char *) filename.c_str ());
130 string class_ptr = string(class_name) +
"*";
131 return get_py_obj (instance, class_ptr.c_str());
140 tuple = PyTuple_New (l);
142 for (
u_int32 i = 0; i < l; i++)
154 PyTuple_SetItem (tuple, i, PyString_FromString (ms.c_str ()));
160 PyTuple_SetItem (tuple, i, PyInt_FromLong (j));
169 u_int32 l = PyTuple_Size (tuple);
171 for (
u_int32 i = 0; i < l; i++)
174 PyObject * item = PyTuple_GetItem (tuple, i);
178 if (PyString_Check (item))
181 string s = python::as_string (item);
186 else if (PyInt_Check (item))
189 u_int32 li = PyInt_AsLong (item);
195 string python::as_string(PyObject *s)
197 #if PY_MAJOR_VERSION >= 3 198 PyObject *byteArr = PyUnicode_AsUTF8String(s);
199 char* str = PyBytes_AsString(byteArr);
201 char* str = PyString_AsString(s);
206 #if PY_MAJOR_VERSION >= 3 211 #if PY_MAJOR_VERSION >= 3 Class to write data from a Gzip compressed file.
static bool exec_file(string filename)
Executes a Python script.
PyObject * globals
Global namespace to use in scripts.
Class to read data from a Gzip compressed file.
static void put_tuple(PyObject *tuple, ogzstream &file)
Save a Python tuple into a file.
#define u_int32
32 bits long unsigned integer
static void show_traceback(void)
Dumps any error information to stderr.
static PyObject * get_tuple(igzstream &file)
Loads a Python tuple previously saved with put_tuple ().
static PyObject * import_module(string filename)
Imports a Python module.
static PyObject * pass_instance(void *instance, const char *class_name)
Magic function that makes any C object available to Python!
Defines the python class. This file is named this way so it doesn't conflicts with Python...
static void insert_path(char *name)
Adds a directory to Python's include path.
static void exec_string(const char *s)
Execute Python statements contained in a string.
static void cleanup()
Cleanup Python.
static void init()
Initialise Python and insert the Adonthell include paths.