unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Getting scheme error informations when running scheme code from C
@ 2005-09-10 13:22 Christian Mauduit
  2005-09-10 14:33 ` Alan Grover
  0 siblings, 1 reply; 9+ messages in thread
From: Christian Mauduit @ 2005-09-10 13:22 UTC (permalink / raw)


Hello,

I'm currently coding a game using scheme as a scripting language. The
main program is a C program which first exports C functions to scheme
and then calls a scheme script. This scheme script is responsible for
all game logic, interaction, control, whatever, and the C functions are
low-level stuff (such as OpenGL graphics, simple core algorithms which
needs to run as fast as possible, and so on).

Of course I'm using Guile for this 8-)

I'm pretty happy with it for now, I'm just discovering Scheme
(previously experienced with Perl, Python and Lua) and it's performing
pretty well. Most of all it does what I need.

But... (there's always a "but...") I find it hard to debug. I assume I'm
not using it the correct way, or that I missed something. Here's my
problem: when there's an error in scheme code, Guile terminates my
program immediately and gives me an error message which is often not
precise enough for proper debugging. Here's an example, with code
excerpts (full code on http://ufoot.hd.free.fr/snapshot/pub/ , project
liquidwar6).

When I run scheme code from C code, placing on purpose an error in the
scheme code (I add a "(car ())" line in some random place) and call it with:
---------8<------------------------------------------------
scm_c_primitive_load (script);
---------8<------------------------------------------------
with script a char * pointing to "src/script/liquidwar6.scm"

I get the following output:
---------8<------------------------------------------------
liquidwar6: registering C functions for Guile
liquidwar6: loading "src/script/liquidwar6.scm"
ERROR: missing or extra expression
---------8<------------------------------------------------
The lines with liquidwar6: are output from my C program, using C log
functions. The line with "ERROR" is an output from Guile, which
terminates the program. As a side note the fact that it terminates the
program is a bit annoying, since I would like to "trap" this message.
Indeed a windows user will never read console output, and if I want
proper bug reports from players, I'd better display this message in a popup.

Then this message is a little "light" for proper debugging. When I'll
have 10000 lines of scheme code, it will be impossible to track bugs
without informations like line number for instance.

Point is if I call "load" are "primitive-load" from the Guile
interpreter I get much more information:

---------8<------------------------------------------------
guile> (load "src/script/liquidwar6.scm")
src/script/loop.scm:20:1: While evaluating arguments to car in
expression (car ()):
src/script/loop.scm:20:1: missing or extra expression
ABORT: (misc-error)

Type "(backtrace)" to get more information or "(debug)" to enter the
debugger.
guile>
---------8<------------------------------------------------

---------8<------------------------------------------------
guile> (primitive-load "src/script/liquidwar6.scm")
src/script/loop.scm:20:1: While evaluating arguments to car in
expression (car ()):
src/script/loop.scm:20:1: missing or extra expression
ABORT: (misc-error)
guile>
---------8<------------------------------------------------

This would be very fine: filename, line number, code excerpt, these are
the very informations I need.

Anyone would have an idea on how to:
1) trap, redirecet or place a hook on the Guile "error handler" (if such
a handler exists?) and get these errors in C, and then decide what to do
with it.
2) actually get precise error informations (file, line, source, error
description) the way the interactive Guile interpreter does.

I read the Guile manual, but:
http://www.gnu.org/software/guile/docs/guile-ref/Debugging-Features.html
and:
http://www.gnu.org/software/guile/docs/guile-ref/Hooks.html
did not solve my problem. At least I couldn't find a solution reading them.

Any clue?

Thanks in advance,

Christian.

-- 
Christian Mauduit <ufoot@ufoot.org>     __/\__ ___
                                        \~/ ~/(`_ \   ___
http://www.ufoot.org/                   /_o _\   \ \_/ _ \_
http://www.ufoot.org/gnupg.pub            \/      \___/ \__)


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2005-09-12 18:49 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-09-10 13:22 Getting scheme error informations when running scheme code from C Christian Mauduit
2005-09-10 14:33 ` Alan Grover
2005-09-10 21:36   ` Christian Mauduit
2005-09-10 23:40     ` Alan Grover
2005-09-11 20:19       ` Christian Mauduit
2005-09-11 21:12         ` Stephen Compall
2005-09-10 23:50     ` Neil Jerram
2005-09-12 12:11       ` Ludovic Courtès
2005-09-12 18:49         ` Neil Jerram

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).