Improve Embedded Python Support
Discussion: https://groups.google.com/d/msg/ledger-cli/kq9sKoRX9vw/fmyhvPslzokJ
This commit is contained in:
parent
a3f3aa304f
commit
af571c1047
5 changed files with 35 additions and 3 deletions
|
|
@ -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_t&>& 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_t&>& 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<>())
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ namespace {
|
|||
|
||||
boost::optional<amount_t>
|
||||
py_commodity_amount_1(const balance_t& balance,
|
||||
const boost::optional<const commodity_t&>& commodity) {
|
||||
const commodity_t& commodity) {
|
||||
return balance.commodity_amount(commodity);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -61,6 +61,8 @@ void export_session()
|
|||
.def("read_journal_files", &session_t::read_journal_files,
|
||||
return_internal_reference<>())
|
||||
.def("close_journal_files", &session_t::close_journal_files)
|
||||
.def("journal", &session_t::get_journal,
|
||||
return_internal_reference<>())
|
||||
;
|
||||
|
||||
scope().attr("session") =
|
||||
|
|
|
|||
|
|
@ -265,6 +265,11 @@ void session_t::close_journal_files()
|
|||
amount_t::initialize();
|
||||
}
|
||||
|
||||
journal_t * session_t::get_journal()
|
||||
{
|
||||
return journal.get();
|
||||
}
|
||||
|
||||
value_t session_t::fn_account(call_scope_t& args)
|
||||
{
|
||||
if (args[0].is_string())
|
||||
|
|
|
|||
|
|
@ -84,6 +84,8 @@ public:
|
|||
journal_t * read_journal_files();
|
||||
void close_journal_files();
|
||||
|
||||
journal_t * get_journal();
|
||||
|
||||
value_t fn_account(call_scope_t& scope);
|
||||
value_t fn_min(call_scope_t& scope);
|
||||
value_t fn_max(call_scope_t& scope);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue