Re: [CM] s7 wrap c func with scheme

2017-02-24 Thread bil

Probably the simplest way to make a C function callable from s7
is to wrap it in a function of the form

s7_pointer wrapper(s7_scheme *sc, s7_pointer args)

Then get the scheme-side arguments from "args", and
wrap the C function's output using the s7_make* functions.
It is then defined in s7 using s7_define_function.
s7.html has an example under "Define a function with arguments".

If you want this in a shared library, you also need to tell
s7's load function how to get the wrappers.  This is normally
done via an environment with a field named 'init_func whose
value is the (name of the) C initialization function in the
library (i.e. the function that calls s7_define_function).
There's an example in the section about libsndlib.so,
but maybe I should add a simpler example.

cload.scm sets up all these wrappers and linkages for you,
but it is overkill for simple cases.

___
Cmdist mailing list
Cmdist@ccrma.stanford.edu
https://cm-mail.stanford.edu/mailman/listinfo/cmdist



[CM] s7 wrap c func with scheme

2017-02-24 Thread James Hearon
Hi,

I had a question about wrapping a c func with scheme, s7.

I'm trying to understand how to wrap the declared function from the .h file 
with scheme in a .scm file (mywrapper.scm) so that it can be called from s7 and 
use the shared library.

> (load mywrapper.scm)
> (myfunction)
> (exit)


I have a .c file which includes a function (myfunction), and .h which declares 
that function.
I compile the .c file using -fpic into an obj. file, then create a shared 
library, ex. mylib.so.

I'm looking at SND files libc.scm and libgsl.scm which seem to be wrappers, but 
are quite complicated.  I'm also looking at the S7 manual example for "Load a 
shared library", but there are static s7_pointer functions in the example's c 
code which seem to be doing the wrapping on the c side as opposed to wrapping a 
c function in scheme using a .scm file.

I'm wondering if there's a simpler example somplace where I can get some ideas 
about how to go about wrapping a c function in scheme, or if the manual vers. 
is the preferred way to go, i.e. create a library using s7 functions from c, 
and then load the library into s7 to call the function?

Regards,
Jim

___
Cmdist mailing list
Cmdist@ccrma.stanford.edu
https://cm-mail.stanford.edu/mailman/listinfo/cmdist