guile-user
[Top][All Lists]
Advanced

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

Re: Using guile to extend gaim


From: Marius Vollmer
Subject: Re: Using guile to extend gaim
Date: 19 Jun 2003 02:28:15 +0200
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3

<address@hidden> 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




reply via email to

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