From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Marius Vollmer Newsgroups: gmane.lisp.guile.user Subject: Re: Using guile to extend gaim Date: 19 Jun 2003 02:28:15 +0200 Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Message-ID: <87of0uzza8.fsf@zagadka.ping.de> References: <52936.66.81.120.226.1055817939.squirrel@webmail.javabsp.org> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1055982748 14440 80.91.224.249 (19 Jun 2003 00:32:28 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Thu, 19 Jun 2003 00:32:28 +0000 (UTC) Cc: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Thu Jun 19 02:32:27 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 19SnLm-0003ki-00 for ; Thu, 19 Jun 2003 02:32:27 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.20) id 19SnJq-0008WD-Gq for guile-user@m.gmane.org; Wed, 18 Jun 2003 20:30:26 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.20) id 19SnJC-0007nb-JL for guile-user@gnu.org; Wed, 18 Jun 2003 20:29:46 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.20) id 19SnJ8-0007YT-1I for guile-user@gnu.org; Wed, 18 Jun 2003 20:29:42 -0400 Original-Received: from mail.dokom.net ([195.253.8.218]) by monty-python.gnu.org with esmtp (Exim 4.20) id 19SnJ3-0007Y4-Rk for guile-user@gnu.org; Wed, 18 Jun 2003 20:29:37 -0400 Original-Received: from dialin.speedway43.dip206.dokom.de ([195.138.43.206] helo=zagadka.ping.de) by mail.dokom.net with smtp (Exim 3.36 #3) id 19SnJG-00062N-00 for guile-user@gnu.org; Thu, 19 Jun 2003 02:29:50 +0200 Original-Received: (qmail 12844 invoked by uid 1000); 19 Jun 2003 00:28:15 -0000 Original-To: In-Reply-To: <52936.66.81.120.226.1055817939.squirrel@webmail.javabsp.org> Original-Lines: 61 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: General Guile related discussions List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.user:2042 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.user:2042 writes: > 1) Because having 2 scheme scripts that interfere with each other is not > very desirable, I am creating an environment to load each script. The > snapshot of the relevant code is here: > > env = scm_make_eval_environment(scm_system_environment->local, > scm_system_environment->imported); > scheme = scm_c_read_string(code); > scm_eval_body(scheme, env); I'm afraid this is not the way to go. The 'environments' are not used at all in Guile at the moment. We have the code, but we have not used them to implement the module system and maybe never will. Also, scm_eval_body evaluates a list of expressions as a body, such as the expressions inside a lambda. I don't think you want that, especially since scm_c_read_string wont return such a list when presented with normal Scheme code. You will want to use 'scm_eval' or 'scm_primitive_eval'. (scm_eval_body should be considered internal. That's a general problem with Guile: a lot of its exported functions would have better be left internal. But that's what you get when you turn a self contained program into a library, I guess...) Worse, the 'env' passed to scm_eval_body is not an 'environment' as constructed by scm_make_eval_environment. It is some internal data structure of the interpreter. (That's why scm_eval_body should be considered internal.) The right way would be to use the (ice-9 safe) module, preferably from Scheme: (use-modules (ice-9 safe)) (define (safe-eval-string string) (eval (with-input-from-string string read) (make-safe-module))) Each call to 'safe-eval-string' will create a new, empty module and evaluate the code in it. The code will only have access to 'safe' Scheme procedures. For example, 'open-output-file' is not available. If you want to allow everything, use (define (make-user-module) (make-module 31 (list (resolve-interface '(guile))))) (define (user-eval-string string) (eval (with-input-from-string string read) (make-user-module))) > 2) How to destroy the environment after it's no longer useful (to > unload a script) For the modules created above, just let them be collected by the GC. (I.e., do nothing.) > 3) Is there an example on calling a generic function with C? As other have said, a generic function can be called like any other function, for example with 'scm_call_0', etc. -- GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3 331E FAF8 226A D5D4 E405 _______________________________________________ Guile-user mailing list Guile-user@gnu.org http://mail.gnu.org/mailman/listinfo/guile-user