[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
26.5 Using C bindings within the interpreter
To be able to get access to foreign functions within the Bigloo interpreter, some extra measurements have to be taken. The foreign functions have to be present in the interpreter binary, which means you have to compile a custom interpreter. Fortunately, this is easy. What has to be done is to wrap the foreign functions within Scheme and make an interpreter module.
Let us consider an example where a C function get_system_time
returning and int
is used in an interpreter. (When linking, be
sure to add the .o
file containing the get_system_time
.)
The ffi-interpreter.scm
file:
(module ExtendendInterpreter (import (wrapper "wrapper.scm")) (main main)) (define (main argv) (repl))
The wrapper.scm
file:
(module wrapper (extern (macro %get-system-time::int () "get_system_time")) (export (get-system-time)) (eval (export-exports)) (define (get-system-time) (%get-system-time))
Compile and link your application with something like:
cc gettime.c -c gettime.o bigloo wrapper.scm -c bigloo ffi-interpreter.scm wrapper.o gettime.o
This document was generated on October 23, 2011 using texi2html 5.0.