[plt-scheme] cffi questions

From: David A. Herman (dherman at ccs.neu.edu)
Date: Thu Jan 1 12:10:04 EST 2004

A few CFFI questions:

1. Is there any way a c-lambda function can access a regular Scheme
function from within the same module? For example:

(module my-lib mzscheme
  (require (lib "cffi.ss" "compiler"))
  (define (local-func a b) (+ a b)
  (define c-func
    (c-lambda (int) int
      "Scheme_Object *lf;
       Scheme_Object *args[2];

       lf = /* somehow look up local-func in this module */
       args[0] = scheme_make_integer(42);
       args[1] = ___arg1;
       ___result = scheme_apply(lf, 2, args);"))
  (provide local-func c-func))

2. Is it safe to access the variables `argc' and `argv' from within a
c-lambda function? They don't seem to be documented, but I've discovered
empirically that those are their names. These variables are needed as
parameters to e.g. the scheme_wrong_type function.

3. Is it a bad idea to make a C header file to separate out struct
definitions, #define's, and the like? I felt like they were cluttering the
Scheme file, but the only way I could figure out to include the header was
to add its directory to the search path at the mzc command line (which is
bad because the -I flag isn't the same for all C compilers).

Many thanks as always,

Posted on the users mailing list.