FFI bindings for SDL 2.0.
sdl2-link provides a fluent API that allows for specifying the native call module and the SDL 2.0 extensions to be loaded. The result of load() is a namespace containing the available functions, constants, macros and structs. The naming follows the SDL 2.0 C API as closely as possible.
- Supports FFI-compatible native call libraries, including fastcall and ffi.
- Supports SDL 2.0 extensions:
- SDL2_image
- SDL2_mixer
- SDL2_ttf
- The SDL 2.0 library must be available through the system's library path.
- Supply an FFI-compatible native call libraries via dependency injection.
npm install sdl2-link
import sdl2link from 'sdl2-link';
const SDL = sdl2link()
.withFastcall(require('fastcall'))
.load();
SDL.SDL_Init(SDL.SDL_INIT_VIDEO);
import sdl2link from 'sdl2-link';
const SDL = sdl2link()
.withFastcall(require('fastcall'))
.withTTF()
.load();
SDL.TTF_Init();
SDL.SDL_Init(SDL.SDL_INIT_VIDEO);
Some of the Joystick and GameController APIs are not compatible with fastcall. All these APIs have been separated out into a separate extension that can only be loaded with ffi. If you are using fastcall, you can safely use ffi to load the joystick extension.
The namespace (object) sdl2-link returns contains constants, structs and functions exactly as they appear in the SDL 2.0 API. Use the official SDL 2.0 documentation for reference.