C interop
C interop
A package can carry native C, Objective-C, and C++ beside its PekoScript. The
sources live under the package's c/ directory and are compiled for each target
as part of the build.
Headers
A .peko.h is a C header that doubles as an FFI surface. The compiler parses it
to learn the functions and types the PekoScript side can call, so the header is
the contract between the two halves.
peko.h is the umbrella header the standard library's C sources compile
against.
Declaring the boundary
A parameter in an FFI signature cannot be named with a reserved word. fn and
in read like ordinary C parameter names and are both taken, so a header using
them fails to parse in a way that points at the wrong place.
Gating per platform
Native sources are gated with the ordinary C preprocessor, using the macros the
toolchain defines for each target, for example __ANDROID__ and
TARGET_OS_IPHONE. The PekoScript side gates with platform blocks instead.
Memory across the boundary
Native code sees managed objects that the collector can move. Read the memory page before writing anything that holds a managed pointer across a call.