minor improvements to python embedding code
[mussa.git] / qui / mussagl.cpp
index 15b01b23a3799fb0a7b83d930cfbdf9cb7cad12f..dcf393b146178300d918aa6b6d912910ee8bf8d4 100644 (file)
@@ -1,6 +1,7 @@
 #include <boost/filesystem/operations.hpp>
 #ifdef USE_PYTHON
 #include <boost/python.hpp>
+namespace py = boost::python;
 #endif
 
 using namespace boost::filesystem;
@@ -35,10 +36,10 @@ int main(int argc, char **argv)
 #ifdef USE_PYTHON
     if (opts.runAsPythonInterpeter) {
       Py_Initialize();
-      boost::python::object main_module((boost::python::handle<>(boost::python::borrowed(PyImport_AddModule("__main__")))));
-      boost::python::object main_namespace = main_module.attr("__dict__");
+      py::object main_module((py::handle<>(py::borrowed(PyImport_AddModule("__main__")))));
+      py::object main_namespace = main_module.attr("__dict__");
 
-      boost::python::handle<> ignored((PyRun_String(
+      py::handle<> ignored((PyRun_String(
                         //"from IPython.Shell import IPShellEmbed\n"
                         //"shell = IPShellEmbed(['mussa'], '')\n",
                         //"import mussa\n"
@@ -50,8 +51,8 @@ int main(int argc, char **argv)
                         main_namespace.ptr(),
                         main_namespace.ptr())
                       ));
-      boost::python::object square = main_module.attr("square");
-      int result = boost::python::extract<int>(square(3));
+      py::object square = main_module.attr("square");
+      int result = py::extract<int>(square(3));
       std::cout << "C++ has " << result << std::endl;
       PyRun_InteractiveLoop(stdin, "mussa");
     } else 
@@ -68,7 +69,7 @@ int main(int argc, char **argv)
     qFatal(e.what());
   }
 #ifdef USE_PYTHON
-  catch (boost::python::error_already_set e) {
+  catch (py::error_already_set e) {
     PyErr_Print();
   }
 #endif /* USE_PYTHON */