SWIG, the Simple Wrapper Interface Generator, is used to create C interfaces for a lot of programming languages. The SWIG version extended with a Forth module can be found on github.
C-headers are parsed and converted to Forth-Sourcecode which uses the previously describe C interface functions.
example.h
example.h
:
%module example %insert("include") { #include "example.h" } %include "example.h"
.fsi-c
file. swig -forth -stackcomments -use-structs -enumcomments -o example-fsi.c example.i
. .fsi-c
file to a .fsx
(x stands for executable) gcc -o example.fsx example-fsi.c
.fs
“Forth Source” file. ./example.fsx -gforth > example.fs
You can find some examples in SWIG’s Forth Example section.
A lot of interface files can be found in Forth Posix C-Interface and Forth C-Interface Modules.
Contribution to the Forth C-Interface Module repository is always welcome.