52class python_module_t :
public scope_t,
public noncopyable
56 boost::python::object module_object;
57 boost::python::dict module_globals;
59 explicit python_module_t(
const string& name);
60 explicit python_module_t(
const string& name, boost::python::object obj);
62 void import_module(
const string& name,
bool import_direct =
false);
64 virtual expr_t::ptr_op_t lookup(
const symbol_t::kind_t kind,
67 void define_global(
const string& name, boost::python::object obj) {
68 module_globals[name] = obj;
71 virtual string description() {
76typedef std::map<PyObject *, shared_ptr<python_module_t> > python_module_map_t;
78class python_interpreter_t :
public session_t
83 shared_ptr<python_module_t> main_module;
84 python_module_map_t modules_map;
86 shared_ptr<python_module_t> import_module(
const string& name) {
87 shared_ptr<python_module_t> mod(
new python_module_t(name));
88 if (name !=
"__main__")
89 main_module->define_global(name, mod->module_object);
93 python_interpreter_t() : session_t(), is_initialized(false) {
96 virtual ~python_interpreter_t() {
103 void hack_system_paths();
105 boost::python::object import_option(
const string& name);
107 enum py_eval_mode_t {
113 boost::python::object eval(std::istream& in, py_eval_mode_t mode = PY_EVAL_EXPR);
114 boost::python::object eval(
const string& str, py_eval_mode_t mode = PY_EVAL_EXPR);
115 boost::python::object eval(
const char * c_str, py_eval_mode_t mode = PY_EVAL_EXPR) {
116 return eval(
string(c_str), mode);
119 value_t python_command(call_scope_t& scope);
125 boost::python::object func;
130 functor_t(boost::python::object _func,
const string& _name)
131 : func(_func), name(_name) {
132 TRACE_CTOR(functor_t,
"boost::python::object, const string&");
134 functor_t(
const functor_t& other)
135 : func(other.func), name(other.name) {
138 virtual ~functor_t() throw() {
141 virtual value_t operator()(call_scope_t& args);
144 option_t<python_interpreter_t> * lookup_option(
const char * p);
146 virtual expr_t::ptr_op_t lookup(
const symbol_t::kind_t kind,
149 OPTION_(python_interpreter_t, import_,
DO_(str) {
150 parent->import_option(str);
154extern shared_ptr<python_interpreter_t> python_session;
#define OPTION_(type, name, body)
#define TRACE_CTOR(cls, args)