chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] noobie question about chicken/swig/csi


From: Tato Norren
Subject: Re: [Chicken-users] noobie question about chicken/swig/csi
Date: Tue, 03 Apr 2007 11:59:44 -0700


On Mon, 2 Apr 2007 11:00:47 +0200, "minh thu" <address@hidden> said:
> 2007/4/2, minh thu <address@hidden>:
> >
> > Hi,
> >
> > For simple things like that, don't use swig.
> > In a .scm file, write this:
> > (define test
> >   (foreign-lambda double "test" double))
> >
> > 'test' is the name in Scheme.
> > "test" is the name in C.
> > The first double is the return type.
> > The last double is the arg.
> >
> > Compile the .scm and the .c files together with csc -s.
> > Note the -s whiwh will make a shared library : a .so file.
> > Now assuming the file were called tt.*, you can bring the function in csi 
> > with
> > csi -require-extension tt
> > or calling (require-extension tt) from a script.
> >
> > For more complete explanation, see here:
> > http://chicken.wiki.br/Interface to external functions and variables
> >
> > There is another way : just use the declaration of your function with
> > foreign-parse, it will automatically make it available in Scheme.
> >
> > Use the Search Box and your left on
> > http://chicken.wiki.br/.
> >
> > Cheers,
> > thu
> >
> 
> Re,
> I forgot to say that you need to declare your function.
> 
> Here an example:
> address@hidden:~/projets/chicken/test$ cat test.c
> /* test.c */
> 
> double
> test( double x )
> {
>   return x * x;
> }
> 
> address@hidden:~/projets/chicken/test$ cat tt.scm
> ; test.scm
> 
> ; you can replace the following with a (foreign-parse ...) ....
> #>
> double test( double );
> <#
> 
> ; ... then you don't need this !
> (define test
>    (foreign-lambda double "test" double))
> address@hidden:~/projets/chicken/test$ csc -s test.c tt.scm
> address@hidden:~/projets/chicken/test$ csi -require-extension tt
> 
>       /    /      /
>  ___ (___    ___ (     ___  ___
> |    |   )| |    |___)|___)|   )
> |__  |  / | |__  | \  |__  |  /
> 
> Version 2.6 - linux-unix-gnu-x86 - [ libffi dload ptables applyhook ]
> (c)2000-2007 Felix L. Winkelmann
> ; loading /home/mt/.csirc ...
> ; loading /usr/local/lib/chicken/1/readline.so ...
> ; loading library regex ...
> ; loading ./tt.so ...
> #;1> (test 5)
> 
> #;1>
> #;1> (test 5)
> 25.0
> #;2> ,q
> 
> Cheers,
> thu

thank you for the reply. i think the '-s' option to csc was what I was
neglecting to use. And now I can even get the SWIG generated code to
work as well. Question about the #> ... <# notation though. It seems
that this shorthand for foreign-declare is built into the main chicken
distribution as well as into the easyffi egg. Is easyffi the 'official'
ffi to use? 
thanks,
Tato N.




reply via email to

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