guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Getting scheme error informations when running scheme code from C


From: Christian Mauduit
Subject: Getting scheme error informations when running scheme code from C
Date: Sat, 10 Sep 2005 15:22:52 +0200
User-agent: Mozilla Thunderbird 1.0.6 (X11/20050803)

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 <address@hidden>     __/\__ ___
                                        \~/ ~/(`_ \   ___
http://www.ufoot.org/                   /_o _\   \ \_/ _ \_
http://www.ufoot.org/gnupg.pub            \/      \___/ \__)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]