Files
javierandClaude Fable 5 09760f99b0 Swift bindings to the Playdate C API
Wraps all ten subsystems of the Playdate SDK 3.1.1 C API (system, display,
graphics, sprites, sound, file, JSON, Lua, scoreboards, network) in
idiomatic Swift: namespaced APIs, wrapper types with ownership semantics,
closures for callbacks, and typed throws. Written within the Embedded Swift
subset so the same code can target the device.

The SDK headers are resolved through a "playdate" pkg-config module
(Scripts/install-pkgconfig.sh), so the package works as a normal SwiftPM
dependency without unsafe build flags.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-24 10:33:45 +02:00

35 lines
927 B
C

//
// CPlaydate.h
// Umbrella header exposing the Playdate C API to Swift.
//
// pd_api.h is resolved through the "playdate" pkg-config module, which
// points at $PLAYDATE_SDK_PATH/C_API. Run Scripts/install-pkgconfig.sh
// once to set that up.
//
#ifndef CPLAYDATE_H
#define CPLAYDATE_H
// The C API only declares the event/system types for extension builds.
#ifndef TARGET_EXTENSION
#define TARGET_EXTENSION 1
#endif
#include "pd_api.h"
// Swift cannot call variadic C function pointers such as
// playdate->system->logToConsole. These shims route a plain string through
// the "%s" format, which also avoids format-string injection.
static inline void cplaydate_log(PlaydateAPI *playdate, const char *message)
{
playdate->system->logToConsole("%s", message);
}
static inline void cplaydate_error(PlaydateAPI *playdate, const char *message)
{
playdate->system->error("%s", message);
}
#endif /* CPLAYDATE_H */