From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: linas@linas.org (Linas Vepstas) Newsgroups: gmane.lisp.guile.user Subject: Re: Embedding guile in a C application. Date: Sun, 30 May 2004 10:45:33 -0500 Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Message-ID: <20040530154533.GV1412@backlot.linas.org> References: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1085931967 30549 80.91.224.253 (30 May 2004 15:46:07 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 30 May 2004 15:46:07 +0000 (UTC) Cc: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sun May 30 17:46:00 2004 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1BUSVc-0008KU-00 for ; Sun, 30 May 2004 17:46:00 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1BUSVk-0004JY-MB for guile-user@m.gmane.org; Sun, 30 May 2004 11:46:08 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1BUSVg-0004JJ-CI for guile-user@gnu.org; Sun, 30 May 2004 11:46:04 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1BUSVe-0004J6-7w for guile-user@gnu.org; Sun, 30 May 2004 11:46:03 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1BUSVd-0004Iz-8b for guile-user@gnu.org; Sun, 30 May 2004 11:46:02 -0400 Original-Received: from [67.100.217.179] (helo=backlot.linas.org) by monty-python.gnu.org with esmtp (Exim 4.34) id 1BUSVF-00087G-Jn for guile-user@gnu.org; Sun, 30 May 2004 11:45:37 -0400 Original-Received: by backlot.linas.org (Postfix, from userid 500) id E7F101BE42; Sun, 30 May 2004 10:45:33 -0500 (CDT) Original-To: Binesh Bannerjee Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.4i X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.4 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.user:3217 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.user:3217 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 yet?) void guile_inner_main(void *closure, int argc, char **argv) { ... your prog ... } int 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); --linas -- pub 1024D/01045933 2001-02-01 Linas Vepstas (Labas!) PGP Key fingerprint = 8305 2521 6000 0B5E 8984 3F54 64A9 9A82 0104 5933 _______________________________________________ Guile-user mailing list Guile-user@gnu.org http://lists.gnu.org/mailman/listinfo/guile-user