[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] Improved API for embedding
From: |
Joerg F. Wittenberger |
Subject: |
Re: [Chicken-users] Improved API for embedding |
Date: |
06 Nov 2003 19:13:50 +0100 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 |
Hi Felix,
in principle, this looks nice. Just for the record, I did _not_ try
to compile your example, I'm afraid it is going to die on the first
assert...
felix <address@hidden> writes:
> Hi!
>
> To simplify the emedding of compiled Scheme code with Chicken, a new source
> file named "default-entry-points.scm" provides a number of boilerplate
> entry points for common tasks. Here an example directly from the manual:
>
> % cat x.scm
> ;;; x.scm
> (include "default-entry-points")
> (define (bar x) (gc) (* x x))
>
> % cat y.c
> /* y.c */
>
> #include "chicken.h"
> #include <assert.h>
>
> int main() {
> char buffer[ 256 ];
> int status;
> C_word val = C_SCHEME_UNDEFINED;
> C_word *data[ 1 ];
> data[ 0 ] = &val;
> CHICKEN_load("z.scm", &status);
> assert(status);
...here, trying to load a file "z.scm", whereby there is only a
"x.scm" available, woudn't it?
;-)
/Jörg
> CHICKEN_read("(bar 99)", &val, &status);
> assert(status);
> C_gc_protect(data, 1);
> printf("data: %08x\n", val);
> CHICKEN_eval_string_to_string("(bar)", buffer, 255, &status);
> assert(!status);
> CHICKEN_get_error_message(buffer, 255);
> printf("ouch: %s\n", buffer);
> CHICKEN_eval_string_to_string("(bar 23)", buffer, 255, &status);
> assert(status);
> printf("-> %s\n", buffer);
> printf("data: %08x\n", val);
> CHICKEN_eval_to_string(val, buffer, 255, &status);
> assert(status);
> printf("-> %s\n", buffer);
> return 0;
> }
>
> % csc x.scm y.c -embedded
> % x
>
> (alas, I just realized default-entry-points.scm doesn't get installed
> automatically.
> So you have to cp that one into your installation directory manually...)
>
>
> cheers,
> felix
>
>
>
> _______________________________________________
> Chicken-users mailing list
> address@hidden
> http://mail.nongnu.org/mailman/listinfo/chicken-users
>
--
The worst of harm may often result from the best of intentions.
http://www.iema.net/article.php?sid=2663
Please AVOID sending me WORD, EXCEL or POWERPOINT attachments.
See http://www.fsf.org/philosophy/no-word-attachments.html
and http://www.newsfactor.com/perl/story/20982.html !