[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Chicken-users] Improved API for embedding
From: |
felix |
Subject: |
[Chicken-users] Improved API for embedding |
Date: |
Wed, 05 Nov 2003 20:13:22 +0100 |
User-agent: |
Opera7.11/Linux M2 build 406 |
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);
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] Improved API for embedding,
felix <=