diff options
author | John Wiegley <johnw@newartisans.com> | 2009-02-24 19:48:14 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-02-24 19:48:14 -0400 |
commit | 0814c5a23f44120088b6139bb7bf1f934f1d1057 (patch) | |
tree | 1c2132245b93881b42b99aa0dd5b7c5d00aff2e0 /src/pyinterp.h | |
parent | 3598abf9d235c24618856d4e0d5092e818e6332e (diff) | |
download | fork-ledger-0814c5a23f44120088b6139bb7bf1f934f1d1057.tar.gz fork-ledger-0814c5a23f44120088b6139bb7bf1f934f1d1057.tar.bz2 fork-ledger-0814c5a23f44120088b6139bb7bf1f934f1d1057.zip |
Added a new level of Python integration
Diffstat (limited to 'src/pyinterp.h')
-rw-r--r-- | src/pyinterp.h | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/src/pyinterp.h b/src/pyinterp.h index 4863cbb9..1b0f4059 100644 --- a/src/pyinterp.h +++ b/src/pyinterp.h @@ -32,7 +32,7 @@ #ifndef _PYINTERP_H #define _PYINTERP_H -#include "scope.h" +#include "interactive.h" #include "session.h" #if defined(HAVE_BOOST_PYTHON) @@ -100,29 +100,36 @@ public: virtual value_t operator()(call_scope_t& args); }; + option_t<python_interpreter_t> * lookup_option(const char * p); + virtual expr_t::ptr_op_t lookup(const string& name); - value_t option_import_(call_scope_t& args) { - path file(args[0].to_string()); + OPTION_(python_interpreter_t, import_, DO_(scope) { + interactive_t args(scope, "s"); + + path file(args.get<string>(0)); - python::object module_sys = import("sys"); - python::object sys_dict = module_sys.attr("__dict__"); + python::object module_sys = parent->import("sys"); + python::object sys_dict = module_sys.attr("__dict__"); - python::list paths(sys_dict["path"]); + python::list paths(sys_dict["path"]); #if BOOST_VERSION >= 103700 - paths.insert(0, file.parent_path().string()); + paths.insert(0, file.parent_path().string()); #else - paths.insert(0, file.branch_path().string()); + paths.insert(0, file.branch_path().string()); #endif - sys_dict["path"] = paths; + sys_dict["path"] = paths; #if BOOST_VERSION >= 103700 - import(file.stem()); + string name = file.filename(); + if (contains(name, ".py")) + parent->import(file.stem()); + else + parent->import(name); #else - import(file.string()); + parent->import(file.leaf()); #endif - return true; - } + }); }; extern shared_ptr<python_interpreter_t> python_session; |