[CM] On FFI bindings

Christos Vagias chris.actondev at gmail.com
Thu Oct 22 10:46:57 PDT 2020


Looks good!

A naive question: how does C behave if you assume that the called function
has a signature
of (s7_scheme* sc) and you try to pass (s7_scheme* sc, s7_pointer args) ?

If the extra argument doesn't cause trouble I guess the init_args could be
always passed (defaulting
to s7_nil if not existing in the passed environment)

Slightly out of topic: just notice the snake case How come it's not
"init-func"?

On Thu, 22 Oct 2020 at 19:17, <bil at ccrma.stanford.edu> wrote:

> It looks like init_args can work:
>
> tlib.c (using linux below):
>
> #include <stdio.h>
> #include <stdlib.h>
> #include "s7.h"
>
> static s7_pointer a_function(s7_scheme *sc, s7_pointer args)
> {
>    return(s7_car(args));
> }
>
> void tlib_init(s7_scheme *sc, s7_pointer args);
> void tlib_init(s7_scheme *sc, s7_pointer args)
> {
>    fprintf(stderr, "tlib_init: %s\n", s7_object_to_c_string(sc, args));
>    s7_define_function(sc, "a-function", a_function, 0, 0, true, "");
> }
>
>
> gcc -fPIC -c tlib.c
> gcc tlib.o -shared -o tlib.so -ldl -lm -Wl,-export-dynamic
>
> /home/bil/cl/ repl
> <1> (load "tlib.so" (inlet 'init_func 'tlib_init 'init_args (list 1 2
> 3)))
> tlib_init: (1 2 3)
> #f
> <2> (a-function 1 2 3)
> 1
>
>
> I think you'll need to remember which form you're using -- if you
> call the no-args init func with args or vice versa, all bets are off.
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cm-mail.stanford.edu/pipermail/cmdist/attachments/20201022/5ae7bcae/attachment.html>


More information about the Cmdist mailing list