From af571c104790b0703d94b0f94b949041cf4f5c1d Mon Sep 17 00:00:00 2001 From: ELIPTUS Date: Wed, 12 Nov 2014 22:51:56 -0800 Subject: Improve Embedded Python Support Discussion: https://groups.google.com/d/msg/ledger-cli/kq9sKoRX9vw/fmyhvPslzokJ --- src/py_account.cc | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'src/py_account.cc') diff --git a/src/py_account.cc b/src/py_account.cc index 3054512e..7b8eda8c 100644 --- a/src/py_account.cc +++ b/src/py_account.cc @@ -35,6 +35,7 @@ #include "pyutils.h" #include "account.h" #include "post.h" +#include "expr.h" namespace ledger { @@ -97,6 +98,26 @@ namespace { return str_to_py_unicode(account.fullname()); } + value_t py_amount_0(const account_t& account) + { + return account.amount(); + } + + value_t py_amount_1(const account_t& account, const boost::optional& expr) + { + return account.amount(expr); + } + + value_t py_total_0(const account_t& account) + { + return account.total(); + } + + value_t py_total_1(const account_t& account, const boost::optional& expr) + { + return account.total(expr); + } + } // unnamed namespace void export_account() @@ -221,8 +242,10 @@ void export_account() .def("xdata", py_xdata, return_internal_reference<>()) - .def("amount", &account_t::amount) - .def("total", &account_t::total) + .def("amount", py_amount_0) + .def("amount", py_amount_1, args("expr")) + .def("total", py_total_0) + .def("total", py_total_1, args("expr")) .def("self_details", &account_t::self_details, return_internal_reference<>()) -- cgit v1.2.3