improve chibi-ffi documentation
Some checks failed
CI / macos-latest (push) Has been cancelled
CI / ubuntu-latest (push) Has been cancelled

Issue #1030.
This commit is contained in:
Alex Shinn 2025-06-26 13:21:04 +09:00
parent 8e2e1bb80e
commit 77a4fbd5ba

View file

@ -1008,6 +1008,13 @@ your platform) and the generated .so file can be loaded directly with
\scheme{load}, or portably using \scheme{(include-shared "file")} in a \scheme{load}, or portably using \scheme{(include-shared "file")} in a
module definition (note that include-shared uses no suffix). module definition (note that include-shared uses no suffix).
You can do this in one step with the \scheme{-c} flag (described
below), and it will compile for you automatically:
\command{
chibi-ffi -c file.stub
}
The goal of this interface is to make access to C types and functions The goal of this interface is to make access to C types and functions
easy, without requiring the user to write any C code. That means the easy, without requiring the user to write any C code. That means the
stubber needs to be intelligent about various C calling conventions stubber needs to be intelligent about various C calling conventions
@ -1015,6 +1022,15 @@ and idioms, such as return values passed in actual parameters.
Writing C by hand is still possible, and several of the core modules Writing C by hand is still possible, and several of the core modules
provide C interfaces directly without using the stubber. provide C interfaces directly without using the stubber.
\subsection{Options}
\itemlist[
\item{\command{-c/--compile} - automatically compile a shared library}
\item{\command{--cc <compiler>} - specify the c compiler executable, default cc}
\item{\command{-f/--flags <flag>} - add a flag to pass to the c compiler, can be used multiple times}
\item{\command{--features <feature>} - comma-delimited list of features to set before loading the stub file, e.g. debug}
]
\subsection{Includes and Initializations} \subsection{Includes and Initializations}
\itemlist[ \itemlist[
@ -1022,6 +1038,7 @@ provide C interfaces directly without using the stubber.
\item{\scheme{(c-system-include header)} - includes the system file \var{header}} \item{\scheme{(c-system-include header)} - includes the system file \var{header}}
\item{\scheme{(c-declare args ...)} - outputs \var{args} directly in the top-level C source} \item{\scheme{(c-declare args ...)} - outputs \var{args} directly in the top-level C source}
\item{\scheme{(c-init args ...)} - evaluates \var{args} as C code after all other library initializations have been performed, with \cvar{ctx} and \cvar{env} in scope} \item{\scheme{(c-init args ...)} - evaluates \var{args} as C code after all other library initializations have been performed, with \cvar{ctx} and \cvar{env} in scope}
\item{\scheme{(c-link lib)} - when automatically compiling with the -c flag, link the given library with -llib}
] ]
\subsection{Struct Interface} \subsection{Struct Interface}
@ -1054,7 +1071,7 @@ The remaining slots are similar to the
except they are prefixed with a C type (described below). The except they are prefixed with a C type (described below). The
\var{c_field_name} should be a field name of \var{struct_name}. \var{c_field_name} should be a field name of \var{struct_name}.
\var{getter-name} will then be bound to a procedure of one argument, a \var{getter-name} will then be bound to a procedure of one argument, a
\{struct_name} type, which returns the given field. If provided, \var{struct_name} type, which returns the given field. If provided,
\var{setter-name} will be bound to a procedure of two arguments to \var{setter-name} will be bound to a procedure of two arguments to
mutate the given field. mutate the given field.