diff options
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | main.py | 13 | ||||
-rw-r--r-- | python.cc | 10 | ||||
-rw-r--r-- | sample.dat | 2 |
4 files changed, 18 insertions, 9 deletions
diff --git a/Makefile.am b/Makefile.am index 098088ee..41c25d4e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -56,7 +56,7 @@ noinst_LIBRARIES = libledger_bpy.a libledger_bpy_a_SOURCES = amount.cc balance.cc value.cc autoxact.cc \ binary.cc config.cc datetime.cc format.cc journal.cc option.cc \ parser.cc qif.cc quotes.cc textual.cc valexpr.cc walk.cc python.cc -libledger_bpy_a_CXXFLAGS = -DUSE_BOOST_PYTHON=1 +libledger_bpy_a_CXXFLAGS = -DUSE_BOOST_PYTHON=1 -DPYTHON_MODULE=1 if READ_GNUCASH libledger_bpy_a_SOURCES += gnucash.cc endif @@ -4,13 +4,13 @@ import time from ledger import * -def foo (str): +def hello (str): print "Hello:", str -def bar (str): +def goodbye (str): print "Goodbye:", str -register_option ("hello", "h:", foo) -register_option ("goodbye", "g:", bar) +register_option ("hello", "h:", hello) +register_option ("goodbye", "g:", goodbye) args = process_arguments (sys.argv[1:]) process_environment (os.environ, "TEST_") @@ -28,7 +28,10 @@ class FormatTransaction (TransactionHandler): def __call__ (self, xact): print self.formatter.format(xact) -handler = FormatTransaction("%D %-20P %N %('foo'100)") +def foo(d, val): + return d.xact.amount + val + +handler = FormatTransaction("%D %-20P %N %('foo'{$100})") handler = FilterTransactions (handler, "/Checking/") expr = parse_value_expr ("a*2") @@ -27,6 +27,8 @@ namespace ledger { python_support * python_interpretor = NULL; +#ifndef PYTHON_MODULE + static struct cleanup_python { ~cleanup_python() { if (python_interpretor) { @@ -56,14 +58,18 @@ void init_module() export_datetime(); } +#endif // PYTHON_MODULE + void init_python() { assert(! python_interpretor); +#ifndef PYTHON_MODULE Py_Initialize(); - python_interpretor = new python_support; - detail::init_module("ledger", &init_module); +#endif + + python_interpretor = new python_support; } } // namespace ledger @@ -4,7 +4,7 @@ ; !python ; from ledger import * ; def foo(d, val): -; return val + d.xact.amount +; return d.xact.amount + val ; !end ; ; --value-expr 'foo'{$100} |