Skip to content

Instantly share code, notes, and snippets.

@ncweinhold
Created March 23, 2014 15:07
Show Gist options
  • Save ncweinhold/9724254 to your computer and use it in GitHub Desktop.
Save ncweinhold/9724254 to your computer and use it in GitHub Desktop.
Example of calling Guile scheme code from C. The scheme code can be modified without recompiling the C code.
(define simple-func
(lambda ()
(display "Script called, now I can change this") (newline)))
(define quick-test
(lambda ()
(display "Adding another function, can modify without recompilation")
(newline)
(adding-without-recompilation)))
(define adding-without-recompilation
(lambda ()
(display "Called this, without recompiling the C code") (newline)))
/*
* Compile using:
* gcc testguile.c \
* -I/usr/local/Cellar/guile/1.8.8/include \
* -D_THREAD_SAFE -L/usr/local/Cellar/guile/1.8.8/lib -lguile -lltdl -lgmp -lm -lltdl -o testguile
*/
#include <stdio.h>
#include <libguile.h>
int main(int argc, char** argv) {
SCM func, func2;
scm_init_guile();
scm_c_primitive_load("script.scm");
func = scm_variable_ref(scm_c_lookup("simple-func"));
func2 = scm_variable_ref(scm_c_lookup("quick-test"));
scm_call_0(func);
scm_call_0(func2);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment