Library
Module
Module type
Parameter
Class
Class type
SDL thin bindings.
Consult the binding conventions, the binding coverage and the quick start.
Given the thinness of the binding most functions are documented by linking directly to SDL's own documentation.
Open the module to use it, this defines only the module Sdl
in your scope.
Note. The module initialization code calls SDL_SetMainReady.
References
module Sdl : sig ... end
SDL bindings.
C names are transformed as follows. The SDL_
is mapped to the module name Sdl
, for the rest add an underscore between each minuscule and majuscule and lower case the result (e.g. SDL_GetError
maps to Sdl.get_error
). Part of the name may also be wrapped by a module, (e.g. SDL_INIT_VIDEO becomes Sdl.Init.video
). If you open Tsdl
, your code will look mostly like SDL code but in accordance with OCaml's programming conventions. Exceptions to the naming convention do occur for technical reasons.
All functions that return an Sdl.result
have the string returned by Sdl.get_error ()
in the Error (`Msg _)
case.
Most bit fields and enumerants are not mapped to variants, they are represented by OCaml values of a given abstract type in a specific module with a composition operator to combine them and a testing operator to test them. The flags for initializing SDL in the module Sdl.Init
is an example of that:
match Sdl.init Sdl.Init.(video + timer + audio) with
| Error _ -> ...
| Ok () -> ...
Using variants in that case is inconvenient for the binding function and of limited use since most of the time bit fields are given to setup state and, as such, are less likley to be used for pattern matching.