PLearn 0.1
|
#include <PythonObjectWrapper.h>
Static Public Member Functions | |
static PyObject * | newPyObject (const VMField &) |
Definition at line 720 of file PythonObjectWrapper.h.
PyObject * PLearn::ConvertToPyObject< VMField >::newPyObject | ( | const VMField & | vmf | ) | [static] |
Definition at line 941 of file PythonObjectWrapper.cc.
References PLearn::PythonObjectWrapper::as(), PLearn::VMField::fieldtype, PLearn::VMField::name, PLERROR, and PLearn::tostring().
{ string pycode = "\nfrom plearn.pybridge.wrapped_plearn_object import VMField\n"; pycode += string("\nresult = VMField(name='") + vmf.name + "', " + "fieldtype=" + tostring(vmf.fieldtype) + ")\n"; PyObject* env = PyDict_New(); if (0 != PyDict_SetItemString(env, "__builtins__", PyEval_GetBuiltins())) PLERROR("In ConvertToPyObject<VMField>::newPyObject : cannot insert builtins in env."); PyObject* res = PyRun_String(pycode.c_str(), Py_file_input, env, env); if (!res) { Py_DECREF(env); if (PyErr_Occurred()) PyErr_Print(); PLERROR("In ConvertToPyObject<VMField>::newPyObject : cannot convert to a VMField."); } Py_DECREF(res); PyObject* py_vmf = PythonObjectWrapper(env).as<std::map<string, PyObject*> >()["result"]; Py_INCREF(py_vmf); Py_DECREF(env); return py_vmf; }