#include "py/python.hpp"
+namespace py = boost::python;
#include <iostream>
+#include <string>
+#include <vector>
-namespace py = boost::python;
+#include <boost/algorithm/string/split.hpp>
+#include <boost/algorithm/string/classification.hpp>
+namespace alg = boost::algorithm;
MussaPython::MussaPython()
{
py::object MussaPython::operator[](std::string name)
{
- std::string code = "reduce(lambda m,n: m.__dict__[n], [__main__] + '";
- code += name;
- code += "'.split('.'))";
- return eval(code);
- /*
- py::object py_name(name);
- py::object name_list = py_name.attr("split")(".");
- int name_list_len = extract<int>(name_list.attr("__len__")());
+ typedef std::vector< std::string > string_vector;
+ string_vector split_name;
+ alg::split(split_name, name, alg::is_any_of("."));
+
py::object lookup = main_namespace["__main__"];
- for(int i=0; i < name_list_len; ++i) {
- lookup = lookup.attr("__dict__")(name_list[i]);
- //std::cout << lookup << std::endl;
+
+ for (string_vector::const_iterator name_i = split_name.begin();
+ name_i != split_name.end();
+ ++name_i)
+ {
+ lookup = lookup.attr("__dict__")[*name_i];
}
return lookup;
- */
}
//! return a reference to a single mussa python interpreter
{
static MussaPython py;
return py;
-}
-
-
+}
\ No newline at end of file