make it possible to build mussa with python
[mussa.git] / qui / mussagl.cpp
index 3d45cb7dc9c164afd1f3ed6a82337aa87e4c6d2c..da1311d0ee15610dc7089ee285a46e3f9856a49c 100644 (file)
@@ -2,6 +2,7 @@
 #ifdef USE_PYTHON
 #include <boost/python.hpp>
 namespace py = boost::python;
+extern "C" void initmussa();
 #endif
 
 using namespace boost::filesystem;
@@ -38,25 +39,8 @@ int main(int argc, char **argv)
   try {
 #ifdef USE_PYTHON
     if (opts.runAsPythonInterpeter) {
+      PyImport_AppendInittab("mussa", &initmussa);
       Py_Initialize();
-      py::object main_module((py::handle<>(py::borrowed(PyImport_AddModule("__main__")))));
-      py::object main_namespace = main_module.attr("__dict__");
-
-      py::handle<> ignored((PyRun_String(
-                        //"from IPython.Shell import IPShellEmbed\n"
-                        //"shell = IPShellEmbed(['mussa'], '')\n",
-                        //"import mussa\n"
-                        "def square(x):\n"
-                        "  r = x * x\n"
-                        "  print 'the square is %d' % (r)\n"
-                        "  return r\n",
-                        Py_file_input, 
-                        main_namespace.ptr(),
-                        main_namespace.ptr())
-                      ));
-      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 
 #endif /* USE_PYTHON */