[racket] Access scheme library from C

From: Daniel Langner (s8572327 at gmail.com)
Date: Mon Dec 2 11:12:35 EST 2013

Hello,

I want to embed the racket interpreter to create a C interface for a 
certain r6rs scheme library. It comprises diverse functions which return 
complex scheme objects. These, in turn, may be passed to other functions 
within the library (and therefore shouldn't be gc'ed along the way).

I got it so far that I call scheme_main_setup, passing along my run 
function which loads the library into the scheme environment and does 
the actual scheme calls. This approach, however, isn't suitable for what 
I want. When run returns, all is gone and gets garbage collected (I think).

I'd rather have a typical interface with an initialization function 
(that loads the environment and returns normally), some wrapper 
functions (which call scheme_dynamic_require and scheme_apply), and a 
destructor function.

Probably I'd have to use scheme_set_stack_base rather than 
scheme_main_setup. Obviously I would want to reuse the environment 
throughout all calls. There hopefully is a way to prevent the garbage 
collector from collecting it, and also the other scheme objects which my 
library returns.

My question is: is this feasible? How would I go about it? Thanks for 
your help!

Regards,
Daniel

Posted on the users mailing list.