* Using guile to extend gaim
@ 2003-06-17 2:45 javabsp
2003-06-17 8:05 ` Andreas Rottmann
2003-06-19 0:28 ` Marius Vollmer
0 siblings, 2 replies; 4+ messages in thread
From: javabsp @ 2003-06-17 2:45 UTC (permalink / raw)
Hi,
I am writing a plugin loader for gaim that would allow people to write
scheme code to extend gaim. For those who don't know, gaim is a
multi-protocol IM client. Its website is at http://gaim.sf.net/ .
I am having a couple issues, hopefully someone on this list will be able
to clearify them for me.
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);
Where code is a char * containing the Scheme code. I wonder if this is the
right way to do it, or if there's a better way?
2) How to destroy the environment after it's no longer useful (to unload a
script)
3) Is there an example on calling a generic function with C?
Thanks,
- Ka-Hing
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Using guile to extend gaim
2003-06-17 2:45 Using guile to extend gaim javabsp
@ 2003-06-17 8:05 ` Andreas Rottmann
2003-06-19 0:28 ` Marius Vollmer
1 sibling, 0 replies; 4+ messages in thread
From: Andreas Rottmann @ 2003-06-17 8:05 UTC (permalink / raw)
Cc: guile-user
<javabsp@javabsp.org> writes:
> 3) Is there an example on calling a generic function with C?
>
You can use simply scm_apply(), IIRC.
Andy
--
Andreas Rottmann | Rotty@ICQ | 118634484@ICQ | a.rottmann@gmx.at
http://www.8ung.at/rotty | GnuPG Key: http://www.8ung.at/rotty/gpg.asc
Fingerprint | DFB4 4EB4 78A4 5EEE 6219 F228 F92F CFC5 01FD 5B62
Packages should build-depend on what they should build-depend.
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Using guile to extend gaim
@ 2003-06-17 14:37 Mike Gran
0 siblings, 0 replies; 4+ messages in thread
From: Mike Gran @ 2003-06-17 14:37 UTC (permalink / raw)
<javabsp@javabsp.org> writes:
> 3) Is there an example on calling a generic function with C?
I don't know if this is right. (The ref manual is a little unclear on what is the right way to do things.) But I've done it this way.
-------------------------------
main.c
-------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <libguile.h>
int main (int argc, char *argv[])
{
SCM func_symbol;
SCM func;
scm_init_guile();
// Load the scheme function definitions
scm_c_primitive_load ("script.scm");
// Call func "do-hello" with 0 args
func_symbol = scm_c_lookup("do-hello");
func = scm_variable_ref(func_symbol);
scm_call_0 (func);
exit(EXIT_SUCCESS);
}
-------------------------------
script.scm
-------------------------------
(define do-hello
(lambda ()
(display "Hello world.")
(newline)))
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Using guile to extend gaim
2003-06-17 2:45 Using guile to extend gaim javabsp
2003-06-17 8:05 ` Andreas Rottmann
@ 2003-06-19 0:28 ` Marius Vollmer
1 sibling, 0 replies; 4+ messages in thread
From: Marius Vollmer @ 2003-06-19 0:28 UTC (permalink / raw)
Cc: guile-user
<javabsp@javabsp.org> 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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2003-06-19 0:28 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-06-17 2:45 Using guile to extend gaim javabsp
2003-06-17 8:05 ` Andreas Rottmann
2003-06-19 0:28 ` Marius Vollmer
-- strict thread matches above, loose matches on Subject: below --
2003-06-17 14:37 Mike Gran
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).