Created
April 8, 2012 09:44
-
-
Save unionx/2336305 to your computer and use it in GitHub Desktop.
C and Guile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <libguile.h> | |
int main(int argc, char** argv) { | |
SCM func; | |
scm_init_guile(); | |
scm_c_primitive_load("c_call_guile.scm"); | |
func = scm_variable_ref(scm_c_lookup("show-me")); | |
scm_call_0(func); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (show-me) | |
(display "script called") | |
(newline)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <libguile.h> | |
SCM c_square(SCM arg) { | |
int c_arg = scm_num2int(arg, 0, NULL); | |
return scm_from_int(c_arg* c_arg); | |
} | |
int main(int argc, char** argv) { | |
SCM func; | |
scm_init_guile(); | |
scm_c_define_gsubr("c_square", 1, 0, 0, c_square); | |
scm_c_primitive_load("guile_call_c.scm"); | |
func = scm_variable_ref(scm_c_lookup("main-script")); | |
scm_call_0(func); | |
return 0; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (main-script) | |
(display (c_square 8)) | |
(newline)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
居然这么简单?!