summaryrefslogtreecommitdiff
path: root/python.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2004-09-14 04:47:41 -0400
committerJohn Wiegley <johnw@newartisans.com>2004-09-14 04:47:41 -0400
commita013b520ba151b9da3adec97d124676a96741b04 (patch)
tree4ee4d75800f9b9dd08c95283212fbdb7c71c1aee /python.cc
parent6c66d1e0ef09f113bca11cfb5ef0f35eebcc61a3 (diff)
downloadfork-ledger-a013b520ba151b9da3adec97d124676a96741b04.tar.gz
fork-ledger-a013b520ba151b9da3adec97d124676a96741b04.tar.bz2
fork-ledger-a013b520ba151b9da3adec97d124676a96741b04.zip
python integrated both ways (see sample.dat), and initialized on-demand
Diffstat (limited to 'python.cc')
-rw-r--r--python.cc78
1 files changed, 78 insertions, 0 deletions
diff --git a/python.cc b/python.cc
new file mode 100644
index 00000000..9699873c
--- /dev/null
+++ b/python.cc
@@ -0,0 +1,78 @@
+#include "python.h"
+#include "ledger.h"
+#include "acconf.h"
+
+#include <boost/python.hpp>
+
+using namespace boost::python;
+
+void export_amount();
+void export_balance();
+void export_value();
+void export_journal();
+void export_parser();
+void export_textual();
+void export_binary();
+void export_qif();
+#ifdef READ_GNUCASH
+void export_gnucash();
+#endif
+void export_option();
+void export_walk();
+void export_format();
+void export_valexpr();
+void export_datetime();
+
+namespace ledger {
+
+python_support * python_interpretor = NULL;
+
+static struct cleanup_python {
+ ~cleanup_python() {
+ if (python_interpretor) {
+ Py_Finalize();
+ delete python_interpretor;
+ }
+ }
+} _cleanup;
+
+void init_module()
+{
+ export_amount();
+ export_balance();
+ export_value();
+ export_journal();
+ export_parser();
+ export_textual();
+ export_binary();
+ export_qif();
+#ifdef READ_GNUCASH
+ export_gnucash();
+#endif
+ export_option();
+ export_walk();
+ export_format();
+ export_valexpr();
+ export_datetime();
+}
+
+void init_python()
+{
+ assert(! python_interpretor);
+
+ Py_Initialize();
+ python_interpretor = new python_support;
+
+#if 1
+ boost::python::detail::init_module("ledger", &init_module);
+#else
+ object m_obj(python_interpretor->main_module);
+ scope current_module(m_obj);
+
+ python_interpretor->main_namespace.attr("bar") = 10;
+
+ handle_exception(init_module_main);
+#endif
+}
+
+} // namespace ledger