Next: , Previous: , Up: FFI  


2 C Declarations

A shim between Scheme and a C toolkit is specified by a case sensitive .cdecl file containing Scheme-like declarations of all relevant toolkit types, constants, and functions. Callback functions to be passed to the toolkit are also specified here.

Each top-level form in the C declaration file must look like one of these:

(include "filename")
(typedef Name any)
(struct Name (Member type) …)
(union Name (Member type) …)
(enum Name (Member) …)
(extern function-type Name (param1 arg-type) …)
(callback callback-type Name (param1 callback-arg-type) …)

The include expression includes another .cdecl file in the current .cdecl file. The string argument is interpreted relative to the current file’s directory.

any can be a type or the word void.

arg-type can be any type except anonymous structs and unions.

function-type can be any arg-type or void.

callback-arg-type can be any type except struct and union types.

callback-type can be any callback-arg-type or void.

type can look like any of these:

Name
basics
(* any)
(enum Name)
(enum Name (Member) …)
(struct Name)
(struct Name (Member type) …)
(union Name)
(union Name (Member type) …)

Name should be defined via a typedef form somewhere in the (included) file(s). It does not have to be defined before it is referenced. It does not have to be defined at all if it is only the target of a pointer type.

basics can be any of the words: char, uchar, short, ushort, int, uint, long, ulong, float, or double (all lowercase).

While the informal grammar above allows anonymous structs to be member types, they are useless outside a named type declaration. The peek and poke (C-> and C->=) syntaxes require a type name (e.g. "GdkEventAny" or "struct _GdkEventAny") before any member names.

(C-include "prhello")

The C-include syntax takes a library name and loads the corresponding -types and -const files at syntax time. This makes the C types and constants available to the other C-... syntax expanders. The form binds c-includes in the syntax environment unless it is already defined there. Thus a (C-include "library") form can be placed at the top of every file with C-... syntax, or loaded into the syntax-time environment of those files.


Next: Alien Data, Previous: Introduction, Up: FFI