[plt-scheme] Linking Scheme- and C-variables
I access c-doubles, for example, by making a closure-like primitive for
each variable:
scheme_add_global( "access-the-double",
scheme_make_closed_prim_w_arity( AccessADouble,
&theDouble,
"access-the-double",
0, 1), e);
AccessADouble is written to return theDouble with
scheme_make_double(theDouble). If a parameter is supplied, it is
validated then stored in theDouble first.
Ie, (access-the-double 12.3) "sets" theDouble to 12.3.
(access-the-double) "gets" 12.3 .
I veered away from the set! route since I don't like the idea of
parallel universes of variables when the two languages are so
different. What happens if a c-double shadows a scheme variable that
is set with (sqrt -1) ?
rac
On Friday, October 31, 2003, at 05:55 PM, Daniel K. Skovenborg wrote:
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
> 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
>
"Don't dip your oar into this sordid sea, Dick; you might be
besmirched."
---Bruce Wayne's advice on Lightweight Languages?