I'm trying to bind Guile to my C application and I have figured out how to execute a scheme script without gh_enter and I have found how to slip C variables into the scheme namespace. However I'm having trouble getting those changed C values back out. Here is the code:
Code:
#include <stdio.h>
#include <guile/gh.h>
void
dostuff (int n, int b, char *s)
{
SCM num;
/* init the guile engine */
scm_init_guile ();
/* define our three vars in the guile context */
gh_define ("num", gh_int2scm(n));
gh_define ("flag", gh_bool2scm(b));
gh_define ("str", gh_str02scm(s));
gh_eval_file ("simple.scm");
num = scm_c_lookup ("num");
printf ("dostuff says %d\n", gh_scm2int (num));
}
int
main (int argc, char **argv)
{
int num = 5;
int bool = 1;
char *str = "Hello World!";
printf ("Starting: %d %d %s\n", num, bool, str);
dostuff (num, bool, str);
printf ("Ending: %d %d %s\n", num, bool, str);
return 0;
}
The following code causes an error of "Error: in procedure gh_scm2_int, Error: wrong type argument in position 1: #<variable 99b50 binding: 10>"
Can anyone help? How do I access a variable that has been changed in the scheme code and am I starting guile and binding c variables properly?
Thanks,
jpbarto