LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-22-2004, 05:23 PM   #1
jpbarto
Senior Member
 
Registered: Mar 2003
Location: Pittsburgh, PA
Distribution: Gentoo / NetBSD
Posts: 1,251

Rep: Reputation: 45
guile / scheme question


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
 
Old 11-22-2004, 08:25 PM   #2
jpbarto
Senior Member
 
Registered: Mar 2003
Location: Pittsburgh, PA
Distribution: Gentoo / NetBSD
Posts: 1,251

Original Poster
Rep: Reputation: 45
Ah! Turns out 'gh_lookup' in place of 'scm_c_lookup' makes everything happy... thanks.

jpbarto
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Guile rpm file won't install from command line or yast2 TdlSnare SUSE / openSUSE 5 12-01-2004 07:36 AM
Guile conflicts kstev715 Linux - Software 1 08-20-2004 09:49 PM
login prompt question & kde scheme question JustinCoyan Slackware 2 06-09-2004 02:02 PM
Scheme Question oulevon Programming 7 07-17-2003 09:04 AM
Sendmail / IP Scheme question jbrochu Linux - Networking 6 05-19-2003 05:47 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration