diff options
author | John Wiegley <johnw@newartisans.com> | 2009-03-03 14:39:07 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-03-03 14:39:07 -0400 |
commit | edf1ccd6ab436c2ab033e1febbe6f91a69abb1fa (patch) | |
tree | 2aa2d9fa04c4d36d120f9959b41f05861f6f948f /src/pyinterp.cc | |
parent | 8da771e331792d298a800a19654db42760b0985e (diff) | |
download | fork-ledger-edf1ccd6ab436c2ab033e1febbe6f91a69abb1fa.tar.gz fork-ledger-edf1ccd6ab436c2ab033e1febbe6f91a69abb1fa.tar.bz2 fork-ledger-edf1ccd6ab436c2ab033e1febbe6f91a69abb1fa.zip |
Added a "python" command, which invokes Py_Main
Diffstat (limited to 'src/pyinterp.cc')
-rw-r--r-- | src/pyinterp.cc | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/pyinterp.cc b/src/pyinterp.cc index 7125a18b..fdc22af9 100644 --- a/src/pyinterp.cc +++ b/src/pyinterp.cc @@ -37,6 +37,8 @@ using namespace python; shared_ptr<python_interpreter_t> python_session; +char * argv0; + void export_amount(); void export_balance(); void export_chain(); @@ -243,6 +245,34 @@ object python_interpreter_t::eval(const string& str, py_eval_mode_t mode) return object(); } +value_t python_interpreter_t::python_command(call_scope_t& args) +{ + if (! is_initialized) + initialize(); + + char ** argv(new char *[args.size() + 1]); + + argv[0] = new char[std::strlen(argv0) + 1]; + std::strcpy(argv[0], argv0); + + for (std::size_t i = 0; i < args.size(); i++) { + string arg = args[i].as_string(); + argv[i + 1] = new char[arg.length() + 1]; + std::strcpy(argv[i + 1], arg.c_str()); + } + + int status = Py_Main(args.size() + 1, argv); + + for (std::size_t i = 0; i < args.size() + 1; i++) + delete[] argv[i]; + delete[] argv; + + if (status != 0) + throw status; + + return NULL_VALUE; +} + option_t<python_interpreter_t> * python_interpreter_t::lookup_option(const char * p) { @@ -268,6 +298,17 @@ expr_t::ptr_op_t python_interpreter_t::lookup(const string& name) return MAKE_OPT_HANDLER(python_interpreter_t, handler); } break; + + case 'p': + if (WANT_PRECMD()) { const char * q = p + PRECMD_PREFIX_LEN; + switch (*q) { + case 'p': + if (is_eq(q, "python")) + return MAKE_FUNCTOR(python_interpreter_t::python_command); + break; + } + } + break; } if (is_initialized && main_nspace.has_key(name.c_str())) { |