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