[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] Constructing parameter lists in C: can I use FFI?
From: |
felix winkelmann |
Subject: |
Re: [Chicken-users] Constructing parameter lists in C: can I use FFI? |
Date: |
Mon, 25 Jul 2005 23:31:58 +0200 |
On 7/25/05, felix winkelmann <address@hidden> wrote:
>
> ;;;; x.scm:
>
> (define-external (foo (int x) (c-string y)) double
> (print (list x y))
> (sqrt x) )
>
> (##sys#call-host)
>
> /* y.c */
>
> #include "chicken.h"
>
> extern double foo(int, char*);
>
> int main()
> {
> CHICKEN_run(NULL, NULL, NULL, C_toplevel);
> C_restore; /* <- pop continuation, unless we call an entry-point
> this should be ok, */
> printf("-> %g\n", foo(42, "abc"));
> printf("-> %g\n", foo(32, "abc"));
> return 0;
> }
>
Here the same example with callbacks (from C to Scheme to C and into Scheme
again):
;;;; x.scm
#>!
___safe double cb1(int x, char *y) { foo(x, y); }
<#
(define-external (foo (int x) (c-string y)) double
(print (list x y))
(sqrt x) )
(define-external (bar (int x) (c-string y)) double
(print "bar: " (list x y))
(cb1 x y) )
(##sys#call-host)
/* y.c */
#include "chicken.h"
extern double foo(int, char*);
int main()
{
CHICKEN_run(NULL, NULL, NULL, C_toplevel);
C_restore; /* <- pop continuation, unless we call an entry-point this
should be ok, */
printf("-> %g\n", foo(42, "abc"));
printf("-> %g\n", bar(32, "def"));
printf("-> %g\n", foo(2, "xyz"));
return 0;
}
cheers,
felix