c-wrapper is a foreign function interface for C and Objective-C libraries. It can parse C header files, so you don't need to define functions, global variables and constants to use libraries.
Sample code
To use c-wrapper, you can write a code like below.
Put magicklib.so, which is generated by cwcompile, on dynamic load paths. And mymodule.scm will load it instead of parsing header files.
Here is a sample movie of c-wrapper and cwcompile.
Restrictions
c-wrapper treats _Bool as int
long double is not available. c-wrapper doesn't report an error if long double exists in prototype declarations, but you can't call the function.
If struct's alignment is changed, the struct member's offset may be wrong.
c-wrapper ignores @property of Objective-C 2.0.
ChangeLog
2009-8-9: release version 0.6.1
Fixed a bug that a renamed function with #define doesn't work.
Fixed a bug that calcs a wrong offset when a struct has a bit-field.
Added support for Cygwin.
2009-6-27: release version 0.6.0
Rewrote C parser to improve c-load performance.
Modified FFI to reduce function calling overhead.
Modified macro handling to handle a macro such like '#define FOO foo()'.
Added :hide-symbols option to c-load.
2009-2-21: release version 0.5.6
Added support for NetBSD x86_64.
Added support of GCC's __attribute__((__mode__(x))).
Added --with-rpath option to configure.
2009-2-14: release version 0.5.5
Added support for Linux x86_64 and FreeBSD x86_64.
Fixed the bug that closure-to-function-pointer conversion doesn't work under NX protection.
Defined setter for <c-ptr>'s ref.
Modified ldconfig-lookup-rule in configure script. If ldconfig doesn't exist in PATH, configure look it up in /sbin and /usr/sbin.
2008-5-11: release version 0.5.4
Added partial support of Objective-C 2.0.
Modified ptr->string and x->string to copy an original string.
2007-5-21: release version 0.5.2
Added ad-hoc support of int*_t and u_int*_t in Linux's /usr/include/sys/types.h.
Added support of GCC's unnamed struct/union fields within structs/unions.
Added deref for <c-func-ptr>.
Adapted to the C99 array type qualifier and array size expression.
2007-1-6: release version 0.5.1
Defined object-apply for function pointers. You can use a function pointer as a procedure.
Fixed the bug of :import keyword in c-load and c-include.
Modified c-load-library and c-ld to recognize '-Wl' option.
Modified cast to convert <foreign-pointer> to <c-ptr>.
Modified ref to handle the indirect component selection. For example, you can use "(ref foo 'bar)" for "foo->bar" in C.
2006-12-26: release version 0.5.0
Added cwcompile command, which generates a shared library. And genwrapper is deprecated.
Added c-load macro, which does c-load-library and c-include at one time.
Added :import keyword option for c-load and c-include. You can specify the symbols you want to define.
Renamed make-c-array to c-array. You can still use the old name, but it will be removed in a future release.
Added define-objc-class and define-objc-method, which defines Objective-C class and method.
Fixed a bug that parsing a function pointer doesn't work correctly in some cases. (Reported by HIBINO Kei)
2006-08-25: release version 0.4.4
Fixed the bug that c-include ignores a macro which references an inline function.
2006-08-20: release version 0.4.3
Fixed the C macro definition algorithm. You can use macros whose bodies uses other macros or whose bodies are statements.
2006-08-06: release version 0.4.2
Add support for inline functions. c-wrapper generates Scheme code from inline function's source code. But it is not supported that an inline function has a label (switch or goto).
2006-07-24: release version 0.4.1
Add c-struct and c-union macro. If you want to reference C struct or union with tagname, use them instead of symbols like <c-struct:...> or <c-union:...>.
Fixed the C macro definition algorithm. In previous versions, some functionlike macros (For example, WhitePixel in X11/Xlib.h) didn't be defined with c-include, but now they have been defined and you can use them.
Fixed a problem with parsing function pointer declaration which don't have an identifier (For example, void (*)((void*)foo)).
2006-06-11: release version 0.4.0
Add support for Intel Mac.
Add support for Objective-C.
Fixed FFI for FreeBSD, you can use functions which return a struct or union.
Pointer objects can have their own finalizers. But be careful to use them because it isn't perfect to inspect whether a pointer is in use or not.
Add the info document. But it's still incomplete.
2006-04-30: release version 0.3.4
The bug that vaargs can't be passed correctly in a certain case is fixed.
2006-04-15: release version 0.3.3
The bug about parsing universal character names is fixed.
2006-04-02: release version 0.3.2
The bug that null-ptr? doesn't work is fixed.
Changed the behavior of #define parser. Functionlike macros are defined as macros, not procedures.
2006-03-25: release version 0.3.1
Add support for bit fields.
c-load-library searches the directories specified by the environment variable LD_LIBRARY_PATH (and DYLD_LIBRARY_PATH in MacOSX).
2006-03-19: release version 0.3.0
c-load-library can recognize .la file.
Add support for functionlike macro.
Replace libffi from GCC 4.0.2's one to GCC 4.1.0's one.
2006-03-12: release version 0.2.0
Add genwrapper command.
Add some features to c-load-library.
Change the way to reference struct and union with tagname. c-struct and c-union are deprecated.
Modify NULL pointer handling. You can pass NULL pointer at a function pointer argument.