Re: [CM] s7 wrap c function with scheme

2017-03-01 Thread bil

ex1.c is the repl from the start of the FFI example
section.  If you build s7 with WITH_MAIN, you don't
need it.

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



[CM] s7 wrap c function with scheme

2017-03-01 Thread James Hearon
Hi,
The wrapper example below works great.  Seems like -DWITH_MAIN, and -DUSE_SND=0 
adds some special help.  Thanks so much for that info.

I'm moving on also to look at cload.scm now, but confused about the s7 manual 
example compile lines which shows an "ex1.c".  I wasn't clear about what is 
ex1.c, or maybe my brain is just not reading the cload example correctly.

gcc -c s7.c -I.
gcc -o ex1 ex1.c s7.o -lm -I. -ldl -Wl,-export-dynamic
ex1
> (load "cload.scm")
...

Regards,
Jim
---
gcc -fpic -c add1.c
gcc -shared -Wl,-soname,libadd1.so -o libadd1.so add1.o -lm -lc
gcc s7.c -o repl -fpic -DWITH_MAIN -I. -ldl -lm -Wl,-export-dynamic -DUSE_SND=0

>./repl
   > (load "libadd1.so" (inlet 'init_func 'add1_init))
   > (add1 2)


#include 
#include "s7.h"

static s7_pointer add1(s7_scheme *sc, s7_pointer args)
{
   if (s7_is_integer(s7_car(args)))
 return(s7_make_integer(sc, 1 + s7_integer(s7_car(args;
   return(s7_wrong_type_arg_error(sc, "add1", 1, s7_car(args), "an integer"));
   }

void add1_init(s7_scheme *sc);
void add1_init(s7_scheme *sc)
{
   s7_define_function(sc, "add1", add1, 1, 0, false, "(add1 int) adds 1 to 
int");
   }

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