Guile API

Alex Weiss alexweiss at theplate.com
Sun Nov 8 11:43:56 EST 2015


I suspected I was going to have to make some sort of patch. Does anyone know if there are plans to expose "qof-session-load" in engine.i in a GnuCash release?   As far as I can see, without it, I have to use the Python API.



> Sent: Sunday, November 08, 2015 at 10:02 AM
> From: "Peter Broadbery" <p.broadbery at gmail.com>
> To: "Alex Weiss" <alexweiss at theplate.com>
> Cc: "John Ralls" <jralls at ceridwen.us>, gnucash-user at gnucash.org
> Subject: Re: Guile API
>
> Hi Alex,
> 
> I've had a similar problem recenty - the begiin function is not
> exported by engine.i, and I had to patch it in.  - see
> https://github.com/pbroadbery/gnucash/commit/688fd2065e23b2b85d8e1c78672a66dbe6234437.
> However, I don't really like this solution as it adds an extra export
> (qof-session-load-0) to engine.i - I couldn't quickly figure out how
> to pass scheme functions to qof_session_load..  I've appended some
> example code.
> 
> There may well be an existing way of doing this as well.
> 
> Regards,
> 
> Peter
> 
> (use-modules (gnucash gnc-module))
> (gnc:module-system-init)
> 
> (cond-expand
>   (guile-2
>     (eval-when
>       (compile load eval expand)
>       (gnc:module-load "gnucash/engine" 0)))
>   (else
>     (gnc:module-load "gnucash/engine" 0)))
> 
> (define (run-test)
>   (let* ((session (qof-session-new)))
>     (qof-session-begin session "file:///tmp/aaa" #t #f #f)
>     (qof-session-load-0 session)
>     (gnc-set-current-session session)
>     (qof-session-get-book session)))
> 
> On 7 November 2015 at 22:21, Alex Weiss <alexweiss at theplate.com> wrote:
> > Thanks for your help.  I saw that code.  However, I seem to be missing something.  While the c function qof_session_new is exposed as qof-session-new, the same is not true for qof_session_begin.
> >
> > In my guile file I include gnucash bindings as so....
> >
> > (use-modules (gnucash gnc-module))
> > (gnc:module-system-init)
> > (gnc:module-load "gnucash/engine" 0)
> >
> > But a call to (qof-session-begin (qof-session-new) "file://agnucashfile.gnucash" #t #f #t)) is considered a call to "Unbound variable: qof-session-begin).
> >
> > Is qof-session-begin in a different module?
> >
> > Thanks for your help again,
> >
> >
> >> Sent: Thursday, October 29, 2015 at 12:14 PM
> >> From: "John Ralls" <jralls at ceridwen.us>
> >> To: "Alex Weiss" <alexweiss at theplate.com>
> >> Cc: gnucash-user at gnucash.org
> >> Subject: Re: Guile API
> >>
> >>
> >> > On Oct 29, 2015, at 8:04 AM, Alex Weiss <alexweiss at theplate.com> wrote:
> >> >
> >> > I was considering scripting GnuCash using its Guile API rather that it's Python API?  Am I crazy to assume that the Guile API is as rich an the Python API?
> >> >
> >> > The first stumbling block I have noticed is simply creating what the Python API calls a "session" - a connection to gnucash will allows for the input and retrieval of GnuCash data. The Python API Session object seems to wraps the c functions: qof_session_new, qof_session_begin, and qof_session_load. The swig interface I found does not seem to export these out as Guile procedures.
> >> >
> >> > Any advice on using the Guile API in general or how to create a session using Guile in particular?
> >>
> >> Alex,
> >>
> >> Actually, more of GnuCash is exposed to Guile than to Python because Python can’t see the parts of GnuCash that are written in Scheme. Everything in the C API that’s exposed to one is exposed to the other; the differences in the SWIG interface files are just customizations needed to make a function work in the language in question. If there’s no customization it means that SWIG can figure out the right thing to do from the C header, and unless a function whose header is included in a SWIG file is specifically %excluded in the SWIG file it’s exported.
> >>
> >> What’s more, GnuCash links libguile and starts the Scheme interpreter very early, so you can actually customize the application with Scheme. This is how one adds custom reports.
> >>
> >> That aside, qof_session_new *is* mentioned explicitly in engine.i outside of the language-specific sections, at line 163. You can see it in action in src/engine/test/test-create-account.scm and test-dcm-query-import.scm
> >>
> >> Regards,
> >> John Ralls
> >
> > _______________________________________________
> > gnucash-user mailing list
> > gnucash-user at gnucash.org
> > https://lists.gnucash.org/mailman/listinfo/gnucash-user
> > -----
> > Please remember to CC this list on all your replies.
> > You can do this by using Reply-To-List or Reply-All.
>



More information about the gnucash-user mailing list