[plt-scheme] Linking Scheme- and C-variables

From: Daniel K. Skovenborg (waldeinburg at yahoo.com)
Date: Fri Oct 31 19:55:54 EST 2003

Hello

I'm making a C-program with embedded MzScheme (used as console) and I like
to have MzScheme so deeply integrated as possible. Therefore I like to
have C-variables linked to Scheme-variables so when you change the
Scheme-variable in the console with set! then the C-variable will change
too and vice versa.

In TCL you can do this with the Tcl_LinkVar C-function, but I can't find
a similar function in MzScheme. Does it exist at all?

Or is the c-pointer Scheme-type the answer? I can make a global
Scheme-variable with scheme_make_cptr and I suppose it points at the
C-variable given to the function, but how do I make it useful after
that?

For example
 int i = 42;
 scheme_add_global( "i", scheme_make_cptr( &i, "number" ), env );
What if I now want to use it with the + primitive. The result of (+ i 2)
is of course
+: expects type <number> as 2nd argument, given: #<c-pointer:number>

I'm sorry, but I RTFM and googled for hours and there doesn't seem to be
much information about this (new?) feature.

Thanks
Daniel K. Skovenborg


Posted on the users mailing list.