[CM] s7 wrap c function with scheme
James Hearon
j_hearon at hotmail.com
Wed Mar 1 10:18:38 PST 2017
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 <stdlib.h>
#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");
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cm-mail.stanford.edu/mailman/private/cmdist/attachments/20170301/9432aaac/attachment.html>
More information about the Cmdist
mailing list