Skip to content

Instantly share code, notes, and snippets.

@unionx
Created April 8, 2012 09:44
Show Gist options
  • Save unionx/2336305 to your computer and use it in GitHub Desktop.
Save unionx/2336305 to your computer and use it in GitHub Desktop.
C and Guile
#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;
}
(define (show-me)
(display "script called")
(newline))
#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;
}
(define (main-script)
(display (c_square 8))
(newline))
@Liutos
Copy link

Liutos commented Apr 8, 2012

居然这么简单?!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment