[Top][All Lists]

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

Re: Embedding guile in a C application.

From: Linas Vepstas
Subject: Re: Embedding guile in a C application.
Date: Sun, 30 May 2004 10:45:33 -0500
User-agent: Mutt/1.5.4i

On Sun, May 30, 2004 at 02:32:56AM -0400, Binesh Bannerjee was heard to remark:
>       I'd like to embed a Guile interpreter inside the app,

Try reading some of teh guile tutorials.

In your C code, you'd want to call scm_c_eval_string () to evaluate a
string e.g. scm_c_eval_string ("(define f (lambda (x) (+ 1 x)))");

Guile also like  to hold the main loop (I don't know why, is this fixed

guile_inner_main(void *closure, int argc, char **argv)
  ... your prog ... 

main (int argc, char **argv)
  scm_boot_guile (argc, argv, guile_inner_main, NULL);

To do your example, below, you would have to write your own
C++ class that assembled stuff into strings, and then called
scm_c_eval_string() on the resulting string.  Caution: you will
find debugging something like the below for syntax errors to be very
very hard.

> /* c = (define f (lambda (x) (+ 1 x))); */
>               cons c = new list_struct();
>               c->add("define");
>               c->add("f");
>               cons c2 = new list_struct();
>               c2->add("lambda");
>               const c3 = new list_struct();
>               c3->add("x");
>               c2->add_list(c3);
>               const c4 = new list_struct();
>               c4->add("+");
>               c4->add("x");
>               c4->add("1");
>               c2->add_list(c4);
>               c->add_list(c2);


pub  1024D/01045933 2001-02-01 Linas Vepstas (Labas!) <address@hidden>
PGP Key fingerprint = 8305 2521 6000 0B5E 8984  3F54 64A9 9A82 0104 5933

reply via email to

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