Preface
This is the reference manual of MoonSDL2, which is a Lua binding library for the Simple DirectMedia Layer 2.0 (SDL2) and its extension libraries SDL_image, SDL_mixer, and SDL_ttf. [1]
It is assumed that the reader is familiar with both SDL2 and the Lua programming language.
For convenience of reference, this document contains external (deep) links to the Lua Reference Manual and the SDL2 wiki.
Getting and installing
For installation intructions, refer to the README file in the MoonSDL2 official repository on GitHub.
Module organization
The MoonSDL2 module is loaded using Lua’s require() and returns a table containing the functions it provides (as usual with Lua modules). This manual assumes that such table is named sdl, i.e. that it is loaded with:
sdl = require("moonsdl2")
but nothing forbids the use of a different name.
Examples
Complete examples can be found in the examples/ directory of the release package.
License
MoonSDL2 is released under the MIT/X11 license (same as Lua, and with the same only requirement to give proper credits to the original author). The copyright notice is in the LICENSE file in the base directory of the official repository on GitHub.
See also
MoonSDL2 is part of MoonLibs, a collection of Lua libraries for graphics and audio programming.
Introduction
MoonSDL2 is an almost one-to-one Lua binding library to SDL2 and its extension libraries. This means that by and large, it is intended to be used as described in the SDL2 documentation (apart from coding in Lua, of course).
Not all SDL2’s APIs are exposed by MoonSDL2. In particular, the following APIs are not (or not yet) exposed: multithreading, file abstraction, shared object support, endianness handling, bit manipulation, platform-specific functionality, and standard library functionality. Moreover, audio functionalities are exposed only in terms of SDL_mixer API bindings (audio device management and audio streams APIs are not exposed).
This section gives a brief overview of the binding library, while the details are given in the sections that follow.
MoonSDL2 binds SDL2 objects (window, renderer, etc.) to Lua userdata, which are returned by the creating functions (sdl.create_window( ), sdl.create_renderer( ), etc) and are then used to refer to objects in Lua in the same way as one would use SDL2 handles in C.
As a general (but loose) rule, SDL2 functions are bound to MoonSDL2 functions or methods whose names are snake_case versions of the original one.
The functions related to an object type - with the exception of the creating function - are usually bounded to methods of that object (e.g. the C function SDL_SetWindowTitle(window, …) becomes the method window:set_title(…) in Lua.
Objects are garbage collected at exit (which includes on error), and automatically deleted at the SDL2 level, so there is no need to explicitly invoke their release methods (free( ), or whatever else) at exit for cleanup.
Apart from at exit, however, objects are not automatically garbage collected [2] and one must release them explicitly when needed, e.g. to release resources when the application is not exiting and some objects are no longer needed.
Releasing an object causes the automatic (pre) destruction of all its children objects, and the invalidation of any reference to the object and to its children. [3]
SDL2 0-based indices are usually translated to 1-based indices in MoonSDL2.
Initialization
hints
Rfr: Configuration Variables.
-
boolean = set_hint(name, value, [priority])
value = get_hint(name)
name, value: string, as per SDL_hints.h,
priority: hintpriority.
The returned value is nil if the hint isn’t set.
Rfr: SDL_SetHint, SDL_SetHintWithPriority, SDL_GetHint.
-
boolean = reset_hint(name)
reset_hints( )
Rfr: SDL_ResetHint, SDL_ResetHints. -
hintcb = add_hint_callback(name, func)
hintcb:del( )
The passed callback func is executed as func(name, oldval, newval), where all arguments are strings (or nil for unset values).
To unregister the callback, use the del( ) method of the returned hintcb object.
Rfr: SDL_AddHintCallback.
Video display
-
numdrivers = get_num_video_drivers( )
name = get_video_drivers(index)
name = get_current_video_driver( )
index: integer (1 .. numdrivers),
name = string.
Rfr: SDL_GetNumVideoDrivers, SDL_GetVideoDriver, SDL_GetCurrentVideoDriver.
-
numdisplays = get_num_displays( )
name = get_display_name(displayindex)
displayindex: integer (1 .. numdisplays),
name = string.
Rfr: SDL_GetNumVideoDisplays, SDL_GetDisplayName.
-
bounds = get_display_bounds(displayindex)
bounds = get_display_usable_bounds(displayindex)
bounds: rect.
Rfr: SDL_GetDisplayBounds, SDL_GetDisplayUsableBounds.
-
ddpi, hdpi, vdpi = get_display_dpi(displayindex)
ddpi, hdpi, vdpi = integers.
Rfr: SDL_GetDisplayDPI.
-
orientation = get_display_orientation(displayindex)
Rfr: SDL_GetDisplayOrientation.
-
{displaymode} = get_display_modes(displayindex)
displaymode = get_current_display_mode(displayindex)
displaymode = get_closest_display_mode(displayindex, displaymode)
displaymode = get_desktop_display_mode(displayindex)
Rfr: SDL_GetDisplayMode, SDL_GetCurrentDisplayMode, SDL_GetClosestDisplayMode, SDL_GetDesktopDisplayMode.
-
displayindex = get_point_display_index(point)
displayindex = get_rect_display_index(rect)
Rfr: SDL_GetPointDisplayIndex, SDL_GetRectDisplayIndex.
-
enable_screen_saver( )
disable_screen_saver( )
boolean = is_screen_saver_enabled( )
Rfr: SDL_EnableScreenSaver, SDL_DisableScreenSaver, SDL_IsScreenSaverEnabled.
window
-
window = create_window(title, [x], [y], w, h, [windowflags])
window = get_grabbed_window( )
window:destroy( )
title: string,
x, y: integers (nil is equivalent to sdl.WINDOWPOS_UNDEFINED),
w, h: integers.
Rfr: SDL_CreateWindow, SDL_GetGrabbedWindow, SDL_DestroyWindow.
-
id = window:get_id( )
windowflags = window:get_flags( )
Rfr: SDL_GetWindowID, SDL_GetWindowFlags.
-
window:set_title(title)
title = window:get_title( )
Rfr: SDL_SetWindowTitle, SDL_GetWindowTitle.
-
window:set_position(x, y)
x, y = window:get_position( )
Rfr: SDL_SetWindowPosition, SDL_GetWindowPosition.
-
window:set_size(w, h)
window:set_minimum_size(w, h)
window:set_maximum_size(w, h)
w, h = window:get_size( )
w, h = window:get_size_in_pixels( )
w, h = window:get_minimum_size( )
w, h = window:get_maximum_size( )
top, left, right, bottom = window:get_borders_size( )
Rfr: SDL_SetWindowSize, SDL_SetWindowMinimumSize, SDL_SetWindowMaximumSize, SDL_GetWindowSize, SDL_GetWindowSizeInPixels, SDL_GetWindowMinimumSize, SDL_GetWindowMaximumSize, SDL_GetWindowBordersSize.
-
window:set_resizable(boolean)
window:set_bordered(boolean)
window:set_always_on_top(boolean)
window:set_input_focus( )
Rfr: SDL_SetWindowResizable, SDL_SetWindowBordered, SDL_SetWindowAlwaysOnTop, SDL_SetWindowInputFocus.
-
window:show( )
window:hide( )
window:raise( )
window:maximize( )
window:minimize( )
window:restore( )
Rfr: SDL_ShowWindow, SDL_HideWindow, SDL_RaiseWindow, SDL_MaximizeWindow, SDL_MinimizeWindow, SDL_RestoreWindow.
-
window:set_fullscreen(mode)
mode: 'real', 'fake', or 'windowed'.
Rfr: SDL_SetWindowFullscreen.
-
window:flash(op)
mode: 'cancel', 'briefly', or 'until focused'.
Rfr: SDL_FlashWindow.
-
window:set_icon(surface)
Rfr: SDL_SetWindowIcon.
-
window:set_grab(boolean)
window:set_keyboard_grab(boolean)
window:set_mouse_grab(boolean)
boolean = window:get_grab( )
boolean = window:get_keyboard_grab( )
boolean = window:get_mouse_grab( )
Rfr: SDL_SetWindowGrab, SDL_SetWindowKeyboardGrab, SDL_SetWindowMouseGrab, SDL_GetWindowGrab, SDL_GetWindowKeyboardGrab, SDL_GetWindowMouseGrab.
-
surface = window:get_surface( )
renderer = window:get_renderer( )
pixelformat = window:get_format( )
Rfr: SDL_GetWindowSurface, SDL_GetWindowRenderer, SDL_GetWindowPixelFormat.
-
window:update_surface( )
window:update_surface_rects({rect})
Rfr: SDL_UpdateWindowSurface, SDL_UpdateWindowSurfaceRects.
-
window:set_brightness(float)
window:set_opacity( )
float = window:get_brightness( )
float = window:get_opacity( )
Rfr: SDL_SetWindowBrightness, SDL_SetWindowOpacity, SDL_GetWindowBrightness, SDL_GetWindowOpacity.
-
window:set_display_mode([displaymode])
displaymode = window:get_display_mode( )
displayindex = window:get_display_index( )
Rfr: SDL_SetWindowDisplayMode, SDL_GetWindowDisplayMode, SDL_GetWindowDisplayIndex.
-
window:set_mouse_rect([rect])
rect = window:get_mouse_rect( )
Rfr: SDL_SetWindowMouseRect, SDL_GetWindowMouseRect.
-
window:set_hit_test([func])
The func callback is executed as result = func(window, area) where area is a point and the returned result must be a hittestresult value.
Passing func=nil disables hit-testing.
Rfr: SDL_SetWindowHitTest.
-
window:set_gamma_ramp([red], [green], [blue])
red, green, blue = window:get_gamma_ramp( )
red, green, blue: {integer}[256] (16-bit unsigned integers).
Rfr: SDL_SetWindowGammaRamp, SDL_GetWindowGammaRamp.
-
window:set_modal_for(parent)
parent: window.
Rfr: SDL_SetWindowModalFor.
glcontext
-
glcontext = gl_create_context(window)
glcontext:delete( )
glcontext:make_current([window])
Rfr: SDL_GL_CreateContext, SDL_GL_DeleteContext, SDL_GL_MakeCurrent.
-
boolean = gl_extension_supported(extension)
extension: string.
Rfr: SDL_GL_ExtensionSupported.
-
gl_set_attribute(glattr, value)
gl_set_boolean_attribute(glattr, boolean)
gl_set_context_version(major, minor, glprofile)
gl_set_context_flags(glcontextflags)
value = gl_get_attribute(glattr)
boolean = gl_get_boolean_attribute(glattr)
major, minor, glprofile = gl_get_context_version( )
glcontextflags = gl_get_context_flags( )
gl_reset_attributes( )
value, major, minor: integer.
Rfr: SDL_GL_SetAttribute, SDL_GL_GetAttribute, SDL_GL_ResetAttributes.
-
window = gl_get_current_window( )
glcontext = gl_get_current_context( )
Rfr: SDL_GL_GetCurrentWindow, SDL_GL_GetCurrentContext.
-
gl_swap_window(window)
window:gl_swap( )
gl_set_swap_interval(swapinterval)
swapinterval = gl_get_swap_interval( )
Rfr: SDL_GL_SwapWindow, SDL_GL_SetSwapInterval, SDL_GL_GetSwapInterval.
-
w, h = gl_get_drawable_size(window)
w, h = window:gl_get_drawable_size( )
w, h: integer.
Rfr: SDL_GL_GetDrawableSize.
Rendering (2D)
Rfr: 2D Accelerated Rendering.
surface
-
surface = create_rgb_surface(width, height, depth, [rmask, gmask, bmask, amask])
surface = create_rgb_surface(width, height, depth, pixelformat)
surface = load_bmp(file)
surface = load_image(file)
surface:free( )
width, height, depth, rmask, gmask, bmask, amask: integer,
file: string (pathname).
Rfr: SDL_CreateRGBSurface, SDL_CreateRGBSurfaceWithFormat, SDL_LoadBMP, IMG_Load, SDL_FreeSurface.
-
surface = surface:duplicate( )
surface = surface:convert(pxlfmt)
surface = surface:convert(pixelformat)
Rfr: SDL_DuplicateSurface, SDL_ConvertSurface, SDL_ConvertSurfaceFormat.
-
surface:save_bmp(file)
surface:save_png(file)
surface:save_jpg(file, quality)
file: string (pathname),
quality: integer.
Rfr: SDL_SaveBMP, IMG_SavePNG, IMG_SaveJPG.
-
pxlfmt = surface:get_pxlfmt( )
pixelformat = surface:get_format( )
w, h, pitch = surface:get_size( )
w, h, pitch: integer.
Rfr: SDL_GetFormat SDL_Surface.
-
surface:set_palette(palette)
Rfr: SDL_SetSurfacePalette.
-
surface:lock( )
surface:unlock( )
boolean = surface:must_lock( )
Rfr: SDL_LockSurface, SDL_UnlockSurface, SDL_MUSTLOCK.
-
surface:set_rle(boolean)
boolean = surface:has_rle( )
Rfr: SDL_SetSurfaceRLE, SDL_HasSurfaceRLE.
-
surface:set_color_key([key])
key = surface:get_color_key( )
boolean = surface:has_color_key( )
key: integer (or nil to disable).
Rfr: SDL_SetColorKey, SDL_GetColorKey, SDL_HasColorKey.
-
surface:set_color_mod(r, g, b)
surface:set_alpha_mod(a)
r, g, b = surface:get_color_mod( )
a, = surface:get_alpha_mod( )
Rfr: SDL_SetSurfaceColorMod, SDL_SetSurfaceAlphaMod, SDL_GetSurfaceColorMod, SDL_GetSurfaceAlphaMod.
-
surface:set_blend_mode(mode)
mode = surface:get_blend_mode( )
mode: integer.
Rfr: SDL_SetSurfaceBlendMode, SDL_GetSurfaceBlendMode.
-
surface:set_clip_rect([rect])
rect = surface:get_clip_rect( )
Rfr: SDL_SetClipRect, SDL_GetClipRect.
-
surface:fill_rect([rect], color)
surface:fill_rects({rect}, color )
Rfr: SDL_FillRect, SDL_FillRects.
-
surface:blit(dst, [srcrect], [dstrect])
surface:blit_scaled(dst, [srcrect], [dstrect])
surface:soft_stretch(dst, [srcrect], [dstrect])
surface:soft_stretch_linear(dst, [srcrect], [dstrect])
dst: surface,
srcrect, dstrect: rect.
Rfr: SDL_BlitSurface, SDL_BlitScaled, SDL_SoftStretch, SDL_SoftStretchLinear.
renderer
-
renderer = create_renderer(window, [index], [rendererflags])
renderer = create_software_renderer(surface)
renderer:destroy( )
index: 1-based index in the table returned by get_render_drivers_info, or nil for the first suitable driver.
Rfr: SDL_CreateRenderer, SDL_CreateSoftwareRenderer, SDL_DestroyRenderer.
-
{renderdriverinfo} = get_render_drivers_info( )
renderdriverinfo = renderer:get_info( )
Rfr: SDL_GetRenderDriverInfo, SDL_GetRendererInfo.
-
window = renderer:get_window( )
Rfr: SDL_RenderGetWindow.
-
renderer:set_vsync(boolean)
Rfr: SDL_RenderSetVSync.
-
renderer:set_target([texture])
texture | nil = renderer:get_target( )
boolean = renderer:target_supported( )
Rfr: SDL_SetRenderTarget, SDL_GetRenderTarget, SDL_RenderTargetSupported.
-
renderer:set_logical_size(w, h)
w, h = renderer:get_logical_size( )
w, h = renderer:get_output_size( )
w, h: integer.
Rfr: SDL_RenderSetLogicalSize, SDL_RenderGetLogicalSize, SDL_GetRendererOutputSize.
-
renderer:set_scale(x, y)
x, y = renderer:get_scale( )
renderer:set_integer_scale(boolean)
boolean = renderer:get_integer_scale( )
x, y: float.
Rfr: SDL_RenderSetScale, SDL_RenderGetScale, SDL_RenderSetIntegerScale, SDL_RenderGetIntegerScale.
-
renderer:set_viewport([rect])
rect = renderer:get_viewport( )
Rfr: SDL_RenderSetViewport, SDL_RenderGetViewport.
-
renderer:set_clip_rect([rect])
rect = renderer:get_clip_rect( )
boolean = renderer:is_clip_enabled( )
Rfr: SDL_RenderSetClipRect, SDL_RenderGetClipRect, SDL_RenderIsClipEnabled.
-
logicalx, logicaly = renderer:window_to_logical(windowx, windowy)
windowx, windowy = renderer:logical_to_window(logicalx, logicaly)
windowx, windowy: integer,
logicalx, logicaly: float.
Rfr: SDL_RenderWindowToLogical, SDL_RenderLogicalToWindow.
-
renderer:clear( )
renderer:present( )
renderer:flush( )
Rfr: SDL_RenderClear, SDL_RenderPresent, SDL_RenderFlush.
-
renderer:set_draw_color(color)
color = renderer:get_draw_color( )
Rfr: SDL_SetRenderDrawColor, SDL_GetRenderDrawColor.
-
renderer:set_draw_blend_mode(mode)
mode = renderer:get_draw_blend_mode( )
mode: integer.
Rfr: SDL_SetRenderDrawBlendMode, SDL_GetRenderDrawBlendMode.
-
renderer:draw_point(x, y)
renderer:draw_point(fpoint)
renderer:draw_points({fpoint})
Rfr: SDL_RenderDrawPointF, SDL_RenderDrawPointsF.
-
renderer:draw_line(x1, y1, x2, y2)
renderer:draw_line(fpoint1, fpoint2)
renderer:draw_lines({fpoint})
Rfr: SDL_RenderDrawLineF, SDL_RenderDrawLinesF.
-
renderer:draw_rect(frect)
renderer:draw_rects({frect})
Rfr: SDL_RenderDrawRectF, SDL_RenderDrawRectsF.
-
renderer:fill_rect([frect])
renderer:fill_rects({frect})
Rfr: SDL_RenderFillRectF, SDL_RenderFillRectsF.
-
renderer:copy(texture, [srcrect], [dstrect])
renderer:copy_ex(texture, [srcrect], [dstrect], [angle], [center], [flipflags])
srcrect: rect,
dstrect: frect,
center: fpoint,
angle: float.
Rfr: SDL_RenderCopyF, SDL_RenderCopyExF.
-
renderer:read_pixels([rect], [pixelformat], pixels, pitch)
pixel: memptr (memory area where to read to),
pitch: integer.
Rfr: SDL_RenderReadPixels.
-
renderer:render_geometry([texture], vertices, [indices] )
verices: {vertex},
indices: {integer} (0-based indices).
Rfr: SDL_RenderGeometry.
texture
-
texture = create_texture(renderer, textureaccess, w, h)
texture = create_texture(renderer, surface)
texture = load_texture(renderer, file)
texture:destroy( )
w, h: integer,
file: string (pathname).
Rfr: SDL_CreateTexture, SDL_CreateTextureFromSurface, IMG_LoadTexture, SDL_DestroyTexture.
-
texture:gl_bind( )
texture:gl_unbind( )
Rfr: SDL_GL_BindTexture, SDL_GL_UnbindTexture.
-
w, h, pixelformat, textureaccess = texture:query( )
w, h: integer.
Rfr: SDL_QueryTexture.
-
texture:set_color_mod(r, g, b)
texture:set_alpha_mod(a)
r, g, b = texture:get_color_mod( )
a = texture:get_alpha_mod( )
r, g, b, a: integer.
Rfr: SDL_SetTextureColorMod, SDL_SetTextureAlphaMod, SDL_GetTextureColorMod, SDL_GetTextureAlphaMod.
-
texture:set_blend_mode(mode)
mode = texture:get_blend_mode( )
mode: integer.
Rfr: SDL_SetTextureBlendMode, SDL_GetTextureBlendMode.
-
texture:set_scale_mode(scalemode)
scalemode = texture:get_scale_mode( )
Rfr: SDL_SetTextureScaleMode, SDL_GetTextureScaleMode.
-
mode = texture:compose_custom_blend_mode(srccolorfactor, dstcolorfactor, colorop, srcalphafactor, dstalphafactor, alphaop)
srccolorfactor, dstcolorfactor: blendfactor,
srcalphafactor, dstalphafactor: blendfactor,
colorop, alphaop: blendoperation,
mode = integer.
Rfr: SDL_ComposeCustomBlendMode.
-
texture:update([rect], pixels, pitch)
texture:update_yuv([rect], yplane, ypitch, uplane, upitch, vplane, vpitch)
texture:update_nv([rect], yplane, ypitch, uvplane, uvpitch)
pixels, yplane, uplane, vplane, uvplane: memptr,
pitch, ypitch, upitch, vpitch, uvpitch: integer.
Rfr: SDL_UpdateTexture, SDL_UpdateYUVTexture, SDL_UpdateNVTexture.
-
pixels, pitch = texture:lock([rect])
surface = texture:lock_to_surface([rect])
texture:unlock( )
pixels: memptr,
pitch: integer.
Rfr: SDL_LockTexture, SDL_LockTextureToSurface, SDL_UnlockTexture.
animation
-
animation = load_animation(file)
animation:free( )
file: string (pathname).
Rfr: IMG_LoadAnimation, IMG_FreeAnimation.
-
w, h = animation:get_size( )
numframes = animation:get_count( )
frames = animation:get_frames( )
delays = animation:get_delays( )
w, h, numframes: integer.
frames: {surface}[numframes],
delays: {integer}[numframes], (milliseconds).
Rfr: IMG_Animation.
pixel format
Note that pxlfmt (an object) corresponds to SDL_PixelFormat, whereas pixelformat (an enum) corresponds to SDL_PixelFormatEnum.
-
pxlfmt:alloc_pxlfmt(pixelformat)
pxlfmt:free( )
Rfr: SDL_AllocFormat, SDL_FreeFormat.
-
pixelformat = pxlfmt:get_format( )
pixel = pxlfmt:map_rgb(r, g, b)
pixel = pxlfmt:map_rgba(r, g, b, a)
r, g, b = pxlfmt:get_rgb(pixel)
r, g, b, a = pxlfmt:get_rgba(pixel)
pixel = integer,
r, g, b, a: integer (0 .. 255).
Rfr: SDL_MapRGB, SDL_MapRGBA, SDL_GetRGB, SDL_GetRGBA.
-
nbits = pxlfmt:bits_per_pixel( )
nbytes = pxlfmt:bytes_per_pixel( )
nbits = bits_per_pixel(pixelformat)
nbytes = bytes_per_pixel(pixelformat)
Rfr: SDL_PixelFormat.
-
pxlfmt:set_palette(palette)
Rfr: SDL_SetPixelFormatPalette.
palette
-
palette = alloc_palette(ncolors)
palette:free( )
ncolors: integer.
Rfr: SDL_AllocPalette.
-
palette:set_colors({color}, firstcolor)
{color} = palette:get_colors( )
ncolors = palette:ncolors( )
ncolors, firstcolor: integer.
Rfr: SDL_SetPaletteColors, SDL_GetPaletteColors.
font
Rfr: SDL2_ttf.
-
font = open_font(file, ptsize, [index])
font = open_font_dpi(file, ptsize, hdpi, vdpi, [index] )
font:close( )
file: string (pathname),
ptsize, hdpi, vdpi: integer.
Rfr: TTF_OpenFont, TTF_OpenFontIndex, TTF_OpenFontDPI, TTF_OpenFontIndexDPI, TTF_CloseFont.
-
font:set_size(ptsize, [hdpi, vdpi])
Rfr: TTF_SetFontSize, TTF_SetFontSizeDPI.
-
font:set_style(ttfstyleflags)
ttfstyleflags = font:get_style( )
Rfr: TTF_SetFontStyle, TTF_GetFontStyle.
-
font:set_outline(integer)
integer = font:get_outline( )
Rfr: TTF_SetFontOutline, TTF_GetFontOutline.
-
font:set_hinting(fonthinting)
fonthinting = font:get_hinting( )
Rfr: TTF_SetFontHinting, TTF_GetFontHinting.
-
integer = font:height( )
integer = font:ascent( )
integer = font:descent( )
integer = font:line_skip( )
Rfr: TTF_FontHeight, TTF_FontAscent, TTF_FontDescent, TTF_FontLineSkip.
-
font:set_kerning(boolean)
boolean = font:get_kerning( )
Rfr: TTF_SetFontKerning, TTF_GetFontKerning.
-
integer = font:faces( )
boolean = font:face_is_fixed_width( )
string = font:face_family_name( )
string = font:face_style_name( )
Rfr: TTF_FontFaces, TTF_FontFaceIsFixedWidth, TTF_FontFaceFamilyName, TTF_FontFaceStyleName.
-
boolean = font:glyph_is_provided(ch)
minx, maxx, miny, maxy, advance = font:glyph_metrics(ch)
integer = font:get_kerning_size(prev_ch, ch)
ch, prev_ch: integer (code point),
minx, maxx, miny, maxy, advance: integer.
Rfr: TTF_GlyphIsProvided32, TTF_GlyphMetrics32, TTF_GetFontKerningSizeGlyphs32.
-
w, h = font:size_text( )
extent, count = font:measure_text(text, maxwidth)
surface = font:render_text_shaded(text, fgcolor, bgcolor, [wraplen])
surface = font:render_text_lcd(text, fgcolor, bgcolor, [wraplen])
surface = font:render_text_solid(text, fgcolor, [wraplen])
surface = font:render_text_blended(text, fgcolor, [wraplen])
text: string,
w, h, extent_, count, maxwidth, wraplen: integer.
fgcolor, bgcolor: color,
Rfr: TTF_SizeText, TTF_MeasureText, TTF_RenderText_Shaded, TTF_RenderText_LCD, TTF_RenderText_Solid, TTF_RenderText_Blended.
-
w, h = font:size_utf8( )
extent, count = font:measure_utf8(text, maxwidth)
surface = font:render_utf8_shaded(text, fgcolor, bgcolor, [wraplen])
surface = font:render_utf8_lcd(text, fgcolor, bgcolor, [wraplen])
surface = font:render_utf8_solid(text, fgcolor, [wraplen])
surface = font:render_utf8_blended(text, fgcolor, [wraplen])
text: string,
w, h, extent_, count, maxwidth, wraplen: integer.
fgcolor, bgcolor: color,
Rfr: TTF_SizeUTF8, TTF_MeasureUTF8, TTF_RenderUTF8_Shaded, TTF_RenderUTF8_LCD, TTF_RenderUTF8_Solid, TTF_RenderUTF8_Blended.
-
surface = font:render_glyph_shaded(ch, fgcolor, bgcolor)
surface = font:render_glyph_lcd(ch, fgcolor, bgcolor)
surface = font:render_glyph_solid(ch, fgcolor)
surface = font:render_glyph_blended(ch, fgcolor)
ch: integer (code point).
fgcolor, bgcolor: color,
Rfr: TTF_RenderGlyph32_Shaded, TTF_RenderGlyph32_LCD, TTF_RenderGlyph32_Solid, TTF_RenderGlyph32_Blended.
-
font:set_sdf(boolean)
boolean = font:get_sdf( )
Rfr: TTF_SetFontSDF, TTF_GetFontSDF.
-
font:set_direction(fontdirection)
font:set_wrapped_align(fontalign)
Rfr: TTF_SetFontDirection, TTF_SetFontWrappedAlign.
-
font:set_script_name(script)
script: string.
Rfr: TTF_SetFontScriptName.
Event handling
-
event | nil = poll_event( )
event = wait_event( )
event | nil = wait_event_timeout(timeout)
timeout: integer (milliseconds).
Rfr: SDL_PollEvent, SDL_WaitEvent, SDL_WaitEventTimeout.
-
push_user_event(code, [data])
code: integer (int32_t),
data: any Lua value (or nil).
When its time come, the event will be dispatched to the user as a userevent.
Rfr: SDL_PushEvent.
-
enable_event(eventtype)
disable_event(eventtype)
state = get_event_state(eventtype)
state: 'enabled' or 'disabled'.
Rfr: SDL_EventState.
Input devices
keyboard
Rfr: Keyboard Support.
Referring to the table at SDL_Scancode, in the following functions name is the Key Name (a string), scancode is the SDL_Scancode Value (an integer), and keycode is the SDL_Keycode Value (also an integer). The sdl table contains sdl.SCANCODE_XXX entries for SDL_SCANCODE_XXX values, and sdl.KEYCODE_XXX entries for SDLK_XXX values.
-
name = get_key_name(keycode)
keycode = get_key_from_name(name)
name = get_scancode_name(scancode)
scancode = get_scancode_from_name(name)
keycode = get_key_from_scancode(scancode)
scancode = get_scancode_from_key(key)
name: string (key name)
scancode integer (sdl.SCANCODE_XXX),
keycode: integer (sdl.KEYCODE_XXX),
Rfr: SDL_GetKeyName, SDL_GetKeyFromName, SDL_GetScancodeName, SDL_GetScancodeFromName, SDL_GetKeyFromScancode, SDL_GetScancodeFromKey.
-
keystate = get_key_state(name)
keystate = get_key_state(scancode)
reset_keyboard( )
Rfr: SDL_GetKeyboardState, SDL_ResetKeyboard.
-
set_mod_state(keymod)
keymod = get_mod_state( )
Rfr: SDL_SetModState, SDL_GetModState.
-
window | nil = get_keyboard_focus( )
Rfr: SDL_GetKeyboardFocus.
-
start_text_input( )
stop_text_input( )
set_text_input_rect([rect])
boolean = is_text_input_active( )
boolean = is_text_input_shown( )
Rfr: SDL_StartTextInput, SDL_StopTextInput, SDL_SetTextInputRect, SDL_IsTextInputActive, SDL_IsTextInputShown.
-
boolean = has_screen_keyboard_support(window)
boolean = is_screen_keyboard_shown( )
Rfr: SDL_HasScreenKeyboardSupport, SDL_IsScreenKeyboardShown.
-
clear_composition( )
Rfr: SDL_ClearComposition.
-
set_clipboard_text([text])
text = get_clipboard_text( )
boolean = has_clipboard_text( )
text: string (nil is equivalent to an empty string).
Rfr: SDL_SetClipboardText, SDL_GetClipboardText, SDL_HasClipboardText.
-
set_primary_selection_text(text)
text = get_primary_selection_text( )
boolean = has_primary_selection_text( )
text: string.
Rfr: SDL_SetPrimarySelectionText, SDL_GetPrimarySelectionText, SDL_HasPrimarySelectionText.
mouse
-
window | nil = get_mouse_focus( )
Rfr: SDL_GetMouseFocus.
-
capture_mouse(boolean)
Rfr: SDL_CaptureMouse.
-
x, y, mousebuttonstate = get_mouse_state( )
x, y, mousebuttonstate = get_global_mouse_state( )
x, y, mousebuttonstate = get_relative_mouse_state( )
Rfr: SDL_GetMouseState, SDL_GetGlobalMouseState, SDL_GetRelativeMouseState.
-
set_relative_mouse_mode(boolean)
boolean = get_relative_mouse_mode( )
Rfr: SDL_SetRelativeMouseMode, SDL_GetRelativeMouseMode.
-
warp_mouse_global(x, y)
warp_mouse_in_window(window, x, y)
Rfr: SDL_WarpMouseGlobal, SDL_WarpMouseInWindow.
cursor
-
cursor = create_cursor(data, mask, w, h, hotx, hoty)
cursor = create_color_cursor(surface, hotx, hoty)
cursor = create_system_cursor(systemcursor)
cursor:free( )
data, mask: memptr,
w, h, hotx, hoty: integer.
Rfr: SDL_CreateCursor, SDL_CreateColorCursor, SDL_CreateSystemCursor.
-
set_cursor([cursor])
cursor | nil = get_cursor( )
cursor | nil = get_default_cursor( )
Rfr: SDL_SetCursor, SDL_GetCursor, SDL_GetDefaultCursor.
-
show_cursor( )
hide_cursor( )
state = cursor_state( )
state: 'shown' or 'hidden'.
Rfr: SDL_ShowCursor, SDL_HideCursor, SDL_CursorState.
joystick
-
joystick = joystick_open(joystickindex)
joystick:close( )
joystickindex: integer(1 .. numjoy).
Rfr: SDL_JoystickOpen, SDL_JoystickClose.
-
joystick = joystick_from_id(joystickid)
joystick = joystick_from_player_index(playerindex)
Rfr: SDL_JoystickFromInstanceID, SDL_JoystickFromPlayerIndex.
-
numjoysticks = num_joysticks( )
string = joystick_name(joystickindex)
joystickguid = joystick_guid(joystickindex)
integer = joystick_vendor(joystickindex)
integer = joystick_product(joystickindex)
integer = joystick_product_version(joystickindex)
joysticktype = joystick_type(joystickindex)
integer = joystick_id(joystickindex)
string = joystick_path(joystickindex)
integer = joystick_player_index(joystickindex)
joystickindex: integer(1 .. numjoysticks).
Rfr: SDL_NumJoysticks, SDL_JoystickNameForIndex, SDL_JoystickGetDeviceGUID, SDL_JoystickGetDeviceVendor, SDL_JoystickGetDeviceProduct, SDL_JoystickGetDeviceProductVersion, SDL_JoystickGetDeviceType, SDL_JoystickGetDeviceInstanceID, SDL_JoystickPath, SDL_JoystickGetDevicePlayerIndex.
-
joystickindex = joystick_attach_virtual(naxes, nbuttons, nhats)
joystick_detach_virtual(joystickindex)
boolean = joystick_is_virtual(joystickindex)
naxes, nbuttons, nhats: integer.
Rfr: SDL_JoystickAttachVirtual, SDL_JoystickDetachVirtual, SDL_JoystickIsVirtual.
-
joystick_event_enable( )
joystick_event_disable( )
state = joystick_event_state( )
joystick_update( )
state: 'enabled' or 'disabled'.
Rfr: SDL_JoystickEventState, SDL_JoystickUpdate.
-
string = joystick_guid_to_string(joystickguid)
joystickguid = joystick_string_to_guid(string)
joystickguidinfo = joystick_guid_info(joystickguid)
Rfr: SDL_JoystickGetGUIDString, SDL_JoystickGetGUIDFromString, SDL_GetJoystickGUIDInfo.
-
string = joystick:get_name( )
joystickguid = joystick:get_guid( )
integer = joystick:get_vendor( )
integer = joystick:get_product( )
integer = joystick:get_product_version( )
string = joystick:get_serial( )
integer = joystick:get_firmware_version( )
joysticktype = joystick:get_type( )
id = joystick:get_id( )
string = joystick:get_path( )
Rfr: SDL_JoystickName, SDL_JoystickGetGUID, SDL_JoystickGetVendor, SDL_JoystickGetProduct, SDL_JoystickGetProductVersion, SDL_JoystickGetSerial, SDL_JoystickGetFirmwareVersion, SDL_JoystickGetType, SDL_JoystickInstanceID, SDL_JoystickPath.
-
joystick:set_player_index([integer])
integer = joystick:get_player_index( )
Rfr: SDL_JoystickSetPlayerIndex, SDL_JoystickGetPlayerIndex.
-
numaxes = joystick:num_axes( )
integer = joystick:get_axis(axis)
integer = joystick:get_axis_initial_state(axis)
joystick:set_virtual_axis(axis, integer)
axis: integer (1 .. numaxes).
Rfr: SDL_JoystickNumAxes, SDL_JoystickGetAxis, SDL_JoystickGetAxisInitialState, SDL_JoystickSetVirtualAxis.
-
numballs = joystick:num_balls( )
dx, dy = joystick:get_ball(ball)
ball: integer (1 .. numballs),
dx, dy: integer.
Rfr: SDL_JoystickNumBalls, SDL_JoystickGetBall.
-
numhats = joystick:num_hats( )
hatstate = joystick:get_hat(hat)
joystick:set_virtual_hat(hat, hatstate)
hat: integer (1 .. numhats),
Rfr: SDL_JoystickNumHats, SDL_JoystickGetHat, SDL_JoystickSetVirtualHat.
-
joystick:rumble(lowfreq, highfreq, durms)
joystick:rumble_triggers(left, right, durms)
boolean = joystick:has_rumble( )
boolean = joystick:has_rumble_triggers( )
Rfr: SDL_JoystickRumble, SDL_JoystickRumbleTriggers, SDL_JoystickHasRumble, SDL_JoystickHasRumbleTriggers.
-
boolean = _joystick:is_haptic( )
Rfr: SDL_JoystickIsHaptic.
-
joystick:set_led(r, g, b)
boolean = joystick:has_led( )
Rfr: SDL_JoystickSetLED, SDL_JoystickHasLED.
-
joystickpowerlevel = joystick:get_current_power_level( )
Rfr: SDL_JoystickCurrentPowerLevel.
-
boolean = joystick:get_attached( )
boolean: string.
Rfr: SDL_JoystickGetAttached.
gamecontroller
-
gamecontroller = gamecontroller_open(joystickindex)
boolean = is_gamecontroller(joystickindex)
gamecontroller:close( )
joystickindex: (1 .. numjoysticks).
Rfr: SDL_GameControllerOpen, SDL_IsGameController, SDL_GameControllerClose.
-
gamecontroller = gamecontroller_from_id(joystickindex)
gamecontroller = gamecontroller_from_player_index(joystickindex)
joystickindex: (1 .. numjoysticks).
Rfr: SDL_GameControllerFromInstanceID, SDL_GameControllerFromPlayerIndex.
-
string = gamecontroller_name(joystickindex)
controllertype = gamecontroller_type(joystickindex)
string = gamecontroller_path(joystickindex)
string = gamecontroller:gamecontroller_mapping(joystickindex)
Rfr: SDL_GameControllerNameForIndex, SDL_GameControllerTypeForIndex, SDL_GameControllerPathForIndex, SDL_GameControllerMappingForDeviceIndex.
-
string = gamecontroller:get_name( )
joystickguid = gamecontroller:get_guid( )
integer = gamecontroller:get_vendor( )
integer = gamecontroller:get_product( )
integer = gamecontroller:get_product_version( )
string = gamecontroller:get_serial( )
integer = gamecontroller:get_firmware_version( )
controllertype = gamecontroller:get_type( )
id = gamecontroller:get_id( )
string = gamecontroller:get_path( )
Rfr: SDL_GameControllerName, SDL_JoystickGetGUID, SDL_GameControllerGetVendor, SDL_GameControllerGetProduct, SDL_GameControllerGetProductVersion, SDL_GameControllerGetSerial, SDL_GameControllerGetFirmwareVersion, SDL_GameControllerGetType, SDL_JoystickInstanceID, SDL_GameControllerPath.
-
gamecontroller:set_player_index([integer])
integer = gamecontroller:get_player_index( )
Rfr: SDL_GameControllerSetPlayerIndex, SDL_GameControllerGetPlayerIndex.
-
gamecontroller_event_enable( )
gamecontroller_event_disable( )
state = gamecontroller_event_state( )
gamecontroller_update( )
state: 'enabled' or 'disabled'.
Rfr: SDL_GameControllerEventState, SDL_GameControllerUpdate.
-
gamecontroller:rumble(lowfreq, highfreq, durms)
gamecontroller:rumble_triggers(left, right, durms)
boolean = gamecontroller:has_rumble( )
boolean = gamecontroller:has_rumble_triggers( )
Rfr: SDL_GameControllerRumble, SDL_GameControllerRumbleTriggers, SDL_GameControllerHasRumble, SDL_GameControllerHasRumbleTriggers.
-
boolean = _gamecontroller:is_haptic( )
Rfr: SDL_JoystickIsHaptic.
-
gamecontroller:set_led(r, g, b)
boolean = gamecontroller:has_led( )
Rfr: SDL_GameControllerSetLED, SDL_GameControllerHasLED.
-
boolean = gamecontroller:get_attached( )
boolean: string.
Rfr: SDL_GameControllerGetAttached.
-
joystick = gamecontroller:get_joystick( )
Rfr: SDL_GameControllerJoystick.
-
string = gamecontroller:get_mapping( )
Rfr: SDL_GameControllerMapping.
-
boolean = gamecontroller:has_axis(controlleraxis)
integer = gamecontroller:get_axis(controlleraxis)
controllerbuttonbind = gamecontroller:get_bind_for_axis(controlleraxis)
Rfr: SDL_GameControllerHasAxis, SDL_GameControllerGetAxis, SDL_GameControllerGetBindForAxis.
-
numtouchpads = gamecontroller:get_num_touchpads( )
numfingers = gamecontroller:get_num_touchpad_fingers(touchpad)
keystate, x, y, pressure = gamecontroller:get_touchpad_finger(touchpad, finger)
touchpad: integer (1 .. numtouchpads),
finger: integer (1 .. numfingers),
x, y, pressure: float.
Rfr: SDL_GameControllerGetNumTouchpads, SDL_GameControllerGetNumTouchpadFingers, SDL_GameControllerGetTouchpadFinger.
-
boolean = gamecontroller:has_sensor(sensortype)
gamecontroller:set_sensor_enabled(sensortype, boolean)
boolean = gamecontroller:is_sensor_enabled(sensortype)
float = gamecontroller:get_sensor_data_rate(sensortype)
data, timestamps = gamecontroller:get_sensor_data(sensortype, numvalues)
numvalues: integer,
data: {float}[numvalues],
timestamps : {integer}[numvalues].
Rfr: SDL_GameControllerHasSensor, SDL_GameControllerSetSensorEnabled, SDL_GameControllerIsSensorEnabled, SDL_GameControllerGetSensorDataRate, SDL_GameControllerGetSensorData.
-
nummappings = gamecontroller_num_mappings( )
string = gamecontroller_mapping_for_index(mapindex)
string = gamecontroller_mapping_for_guid(joystickguid)
rc = gamecontroller_add_mapping(string)
n = gamecontroller_add_mappings_from_file(file)
mapindex: integer (1 .. nummappings),
rc = 'added' or 'updated',
file: string (pathname).
Rfr: SDL_GameControllerNumMappings, SDL_GameControllerMappingForIndex, SDL_GameControllerMappingForGUID, SDL_GameControllerAddMapping, SDL_GameControllerAddMappingsFromFile.
haptic
-
haptic = haptic_open(hapticindex)
haptic = haptic_open(joystick)
haptic = haptic_open(gamecontroller)
haptic = haptic_open_from_mouse( )
haptic:close( )
hapticindex: integer(1 .. numhaptics).
Rfr: SDL_HapticOpen, SDL_HapticOpenFromJoystick, SDL_HapticOpenFromMouse, SDL_HapticClose.
-
numhaptics = num_haptics( )
boolean = mouse_is_haptic( )
boolean = is_haptic_opened(hapticindex)
string = haptic_name(hapticindex)
hapticindex: integer(1 .. numhaptics).
Rfr: SDL_NumHaptics, SDL_MouseIsHaptic, SDL_HapticOpened, SDL_HapticName.
-
hapticindex = haptic:get_index( )
string = haptic:get_name( )
hapticfeatures = haptic:query( )
Rfr: SDL_HapticIndex, SDL_HapticName, SDL_HapticQuery.
-
numeffects haptic:num_effects( )
numeffects haptic:num_effects_playing( )
boolean = haptic:effect_supported(hapticeffect)
id = haptic:new_effect(hapticeffect)
haptic:update_effect(id , hapticeffect)
haptic:destroy_effect(id)
haptic:run_effect(id, [iterations=1])
haptic:run_effect_indefinitely(id)
haptic:stop_effect(id)
boolean = haptic:is_effect_running(id)
id: integer,
iterations: integer.
Rfr: SDL_HapticNumEffects, SDL_HapticNumEffectsPlaying, SDL_HapticEffectSupported, SDL_HapticNewEffect, SDL_HapticUpdateEffect, SDL_HapticDestroyEffect, SDL_HapticRunEffect, SDL_HapticStopEffect, SDL_HapticGetEffectStatus.
-
numaxes haptic:num_axes( )
Rfr: SDL_HapticNumAxes.
-
haptic:set_gain(integer)
haptic:set_autocenter(integer)
Rfr: SDL_HapticSetGain, SDL_HapticSetAutocenter.
-
haptic:pause( )
haptic:resume( )
haptic:stop_all( )
Rfr: SDL_HapticPause, SDL_HapticUnpause, SDL_HapticStopAll.
-
haptic:rumble_init( )
haptic:rumble_play(strength, duration)
haptic:rumble_stop( )
boolean = haptic:rumble_supported( )
strength: float,
duration: integer.
Rfr: SDL_HapticRumbleInit, SDL_HapticRumblePlay, SDL_HapticRumbleStop, SDL_HapticRumbleSupported.
touch
-
{touchdevice} = get_touch_devices( )
Rfr: SDL_GetTouchDevices.
-
finger = get_touch_finger(touch_id, index)
index = integer (_1 .. num_fingers).
Rfr: SDL_GetTouchFinger.
-
record_gesture([touch_id=-1])
save_dollar_template(gesture_id, file)
numsaved = save_all_dollar_templates(file)
numloaded = load_dollar_templates(touch_id, file)
file: string (pathname),
numsaved, numloaded: integer,
gesture_id, touch_id_: integer.
Rfr: Dollar Gestures, SDL_RecordGesture, SDL_SaveDollarTemplate, SDL_SaveAllDollarTemplates, SDL_LoadDollarTemplates.
sensor
-
sensor = sensor_open(sensorindex)
sensor = sensor_open_from_id(id)
sensor:close( )
sensorindex: integer (1 .. numsensors),
id: integer.
Rfr: SDL_SensorOpen, SDL_SensorFromInstanceID, SDL_SensorClose.
-
string = sensor:get_name( )
sensortype = sensor:get_type( )
sensortype = sensor:get_non_portable_type( )
id = sensor:get_id( )
data, timestamps = sensor:get_data( )
id: integer,
data: {float}[numvalues],
timestamps : {integer}[numvalues].
Rfr: SDL_SensorGetName, SDL_SensorGetType, SDL_SensorGetNonPortableType, SDL_SensorGetInstanceID, Rfr: SDL_SensorGetData.
-
sensor_update( )
Rfr: SDL_SensorUpdate.
-
numsensors = num_sensors( )
string | nil = sensor_name(sensorindex)
id = sensor_id(sensorindex)
sensortype = sensor_type(sensorindex)
sensortype = sensor_non_portable_type(sensorindex)
numsensors: integer,
sensorindex: integer (1 .. numsensors),
id: integer.
Rfr: SDL_NumSensors, SDL_SensorGetDeviceName, SDL_SensorGetDeviceInstanceID, SDL_SensorGetDeviceType, SDL_SensorGetDeviceNonPortableType.
Audio mixer
Rfr: SDL2_mixer.
Note
|
SDL_mixer uses the term 'channel' to refer both to audio channels (mono/stereo/surround), and to separate sources of audio data. To avoid confusion, the latter are here renamed as tracks. |
-
open_audio(frequency, [audioformat], channels, chunksize)
close_audio( )
The following definitions are available: sdl.MIX_DEFAULT_FREQUENCY, sdl.MIX_DEFAULT_FORMAT, and sdl.MIX_DEFAULT_CHANNELS.
Rfr: Mix_OpenAudio, Mix_CloseAudio.
-
open, frequency, audioformat, channels = query_audio( )
boolean = has_chunk_decoder( )
boolean = has_music_decoder( )
{string} = get_chunk_decoders( )
{string} = get_music_decoders( )
open: boolean,
frequency, channels: integer.
Rfr: Mix_QuerySpec, Mix_HasChunkDecoder, Mix_HasMusicDecoder, Mix_GetChunkDecoder, Mix_GetMusicDecoder.
-
set_master_volume(value)
value = get_master_volume( )
value: integer (0 .. sdl.MIX_MAX_VOLUME).
Rfr: Mix_MasterVolume.
-
set_sound_fonts([paths])
paths | nil = get_sound_fonts( )
boolean = each_sound_font(func)
paths: string.
The func callback is executed as boolean = func(path).
Rfr: Mix_SetSoundFonts, Mix_GetSoundFonts, Mix_EachSoundFont.
tracks
-
numtracks = num_tracks( )
allocate_tracks(n)
n = reserve_tracks(n)
Rfr: Mix_AllocateChannels, Mix_ReserveChannels.
-
track_set_panning([track], left, right)
track_unset_panning([track])
track: integer, or nil for all tracks.
left, right: integer (0 .. 255).
Rfr: Mix_SetPanning.
-
track_set_distance([track], distance)
track_set_position([track], angle, distance)
angle, distance: integer.
Rfr: Mix_SetDistance, Mix_SetPosition.
-
track_set_reverse_stereo([track], flip)
flip: boolean.
Rfr: Mix_SetReverseStereo.
-
track_set_volume([track], value)
value = track_get_volume([track])
value: integer (0 .. sdl.MIX_MAX_VOLUME).
Rfr: Mix_Volume.
-
track_halt([track])
track_pause([track])
track_resume([track])
boolean, n = track_paused([track])
boolean, n = track_playing([track])
n: integer (no. of tracks in the queried state, returned only if track=nil).
Rfr: Mix_HaltChannel, Mix_Pause, Mix_Resume, Mix_Paused, Mix_Playing.
-
n = track_expire([track], [ms])
ms: integer (milliseconds), or nil to remove the expiration.
n: integer (no. of channels that changed expirations).
Rfr: Mix_ExpireChannel.
-
boolean = track_fading(track)
track_fade_out([track], ms)
track_fade_in([track], ms, chunk, [loopms=0], [maxms=-1])
Rfr: Mix_FadingChannel, Mix_FadeOutChannel, Mix_FadeInChannel, Mix_FadeInChannelTimed.
-
chunk | nil = track_get_chunk(track)
Rfr: Mix_GetChunk.
-
set_track_finished_callback([func])
The func callback is executed as func(track).
Passing func=nil unregisters the callback.
Rfr: Mix_ChannelFinished.
-
group_add(tag, track)
group_add(tag, fromtrack, totrack)
group_remove(track)
group_remove(fromtrack, totrack)
ntracks = group_count(tag)
tag: integer (tag = -1 is reserved for removal operations).
Rfr: Mix_GroupChannels Mix_GroupCount.
-
track | nil = group_available(tag)
track | nil = group_oldest(tag)
track | nil = group_newest(tag)
Rfr: Mix_GroupAvailable, Mix_GroupOldest, Mix_GroupNewer.
-
group_halt(tag)
group_fade_out(tag, ms)
Rfr: Mix_HaltGroup, Mix_FadeOutGroup.
chunks
-
chunk = load_wav(file)
chunk:free( )
file: string (pathname).
Rfr: Mix_LoadWav, Mix_FreeChunk.
-
track = chunk:play([track], [loops=0], [maxms=-1])
Rfr: Mix_PlayChannel, Mix_PlayChannelTimed.
-
track = chunk:fade_in(ms, [track], [loopms=0], [maxms=-1])
Rfr: Mix_FadeInChannel, Mix_FadeInChannelTimed.
-
chunk:set_volume(value)
value = chunk:get_volume( )
value: integer (0 .. sdl.MIX_MAX_VOLUME).
Rfr: Mix_VolumeChunk.
music
-
music = load_music(file)
music:free( )
file: string (pathname).
Rfr: Mix_LoadMUS, Mix_FreeMusic.
-
musictype = music:get_type( )
string = music:get_title( )
string = music:get_title_tag( )
string = music:get_artist_tag( )
string = music:get_album_tag( )
string = music:get_copyright_tag( )
Rfr: Mix_GetMusicType, Mix_GetMusicTitle, Mix_GetMusicTitleTag, Mix_GetMusicArtistTag, Mix_GetMusicAlbumTag, Mix_GetMusicCopyrightTag.
-
music:play([loops=0])
music:halt( )
music:pause( )
music:resume( )
music:rewind( )
boolean = music:paused( )
boolean = music:playing( )
music_halt( )
music_pause( )
music_resume( )
music_rewind( )
boolean = music_paused( )
boolean = music_playing( )
Rfr: Mix_PlayMusic, Mix_HaltMusic, Mix_PauseMusic, Mix_ResumeMusic, Mix_RewindMusic, Mix_PausedMusic, Mix_PlayingMusic.
-
music:fade_in(ms, [position=0.0], [loops=0])
playing = music:fade_out(ms)
boolean = music:fading( )
playing = music_fade_out(ms)
boolean = music_fading( )
position: float (seconds),
playing: boolean.
Rfr: Mix_FadeInMusic, Mix_FadeInMusicPos, Mix_FadeOutMusic, Mix_FadingMusic.
-
music:set_volume(value)
value = music:get_volume( )
music_set_volume(value)
value = music_get_volume( )
value: integer (0 .. sdl.MIX_MAX_VOLUME).
Rfr: Mix_SetVolumeMusic, Mix_GetVolumeMusic.
-
music:set_position(value)
music_set_position(value)
value = music:get_position( )
value = music:get_duration( )
value = music:get_loop_start_time( )
value = music:get_loop_end_time( )
value = music:get_loop_length_time( )
value: float (seconds).
Rfr: Mix_SetMusicPosition, Mix_GetMusicPosition, Mix_MusicDuration, Mix_GetMusicLoopStartTime, Mix_GetMusicLoopEndTime, Mix_GetMusicLoopLengthTime.
-
set_music_finished_callback([func])
The func callback is executed as func( ).
Passing func=nil unregisters the callback.
Rfr: Mix_HookMusicFinished.
Time handling
ticks
-
ticks = get_ticks( )
ticks = ticks_passed(t1, t2)
delay(ticks)
ticks, t1, t2: integer (milliseconds).
Rfr: SDL_GetTicks, SDL_PASSED, SDL_Delay.
-
ticks = get_performance_counter( )
tickspersecond = get_performance_frequency( )
Rfr: SDL_GetPerformanceCounter, SDL_GetPerformanceFrequency.
The following alternative time utilities are also available (they are consistent with the time utilities that can be found in other libraries of the MoonLibs collection).
-
t = now( )
Returns the current time in seconds (float).
The returned time is relative to an unspecified point in the past, and unrelated to the time in milliseconds returned by get_ticks( ).
This is implemented with monotonic clock_gettime(3), if available, or with gettimeofday(3) otherwise.
-
dt = since(t)
Returns the time in seconds (float) elapsed since the time t, previously obtained with now( ).
-
sleep(seconds)
Sleeps for seconds (float).
timer
-
timer = start_timer(timeout, func)
timer:stop( )
timeout: integer (milliseconds).
The func callback is executed at the expiration of the timer as restart = func(timer).
If the callback returns false (or nil), the timer is deleted, othewise it is restarted with the same timeout value.
The stop( ) method stops and deletes the timer.
Rfr: SDL_AddTimer.
Miscellanea
messagebox
-
messagebox = create_message_box(messageboxdata)
messagebox:set_color_scheme([colors])
buttonid = messagebox:show( )
messagebox:delete( )
buttonid: integer (identifying the pressed button),
colors: {color}[5], defining (in this order) the color of 1) background, 2) text, 3) button border, 4) button background, and 5) button selected. Only the rgb components are relevant (any alpha component is ignored). Pass colors=nil to restore the default color scheme.
Rfr: SDL_ShowMessageBox.
-
show_simple_message_box(messageboxflags, title, message, [window])
title, message: string.
Rfr: SDL_ShowSimpleMessageBox.
rectangle functions
Rfr: Rectangle Functions.
-
boolean = point_in_rect(fpoint, frect)
boolean = rect_empty(frect)
boolean = rect_equals(frect1, frect2, [epsilon])
boolean = has_intersection(frect1, frect2)
frect | nil = intersect_rect(frect1, frect2)
frect = union_rect(frect1, frect2)
boolean, frect = enclose_points({fpoint}, [frectclip])
nil | x1, y1, x2, y2 = intersect_rect_and_line(frect, x1, y1, x2, y2)
nil | fpoint1, fpoint2 = intersect_rect_and_line(frect, fpoint1, fpoint2)
epsilon: float.
Rfr: SDL_PointInFRect, SDL_FRectEmpty, SDL_FRectEquals, SDL_FRectEqualsEpsilon, SDL_HasIntersectionF, SDL_IntersectFRect, SDL_UnionFRect, SDL_EncloseFPoints, SDL_IntersectFRectAndLine.
log functions
Rfr: Log Handling.
-
log_set_priority(category, priority)
log_set_all_priority(priority)
log_reset_priorities( )
priority = log_get_priority(category)
category: logcategory or integer (for custom categories),
priority: logpriority.
Rfr: SDL_SetPriority, SDL_SetAllPriority, SDL_ResetPriority, SDL_GetPriority.
-
log(message)
log_verbose(category, message)
log_debug(category, message)
log_info(category, message)
log_warn(category, message)
log_error(category, message)
log_critical(category, message)
log_message(category, priority, message)
message: string,
category: logcategory or integer (for custom categories),
priority: logpriority.
Rfr: SDL_Log, SDL_LogVerbose, SDL_LogDebug, SDL_LogInfo, SDL_LogWarn, SDL_LogError, SDL_LogCritical, SDL_LogMessage.
-
log_set_output_function([func])
The passed callback func is executed as func(category, priority, message).
Passing func=nil unregisters the callback.
SDL_LogSetOutputFunction.
other functions
-
trace_objects(boolean)
Enable/disable tracing of objects creation and destruction (which by default is disabled).
If enabled, a printf is generated whenever an object is created or deleted, indicating the object type and the value of its raw SDL2 handle.
-
string = get_platform( )
Rfr: SDL_GetPlatform.
-
secs, pct = get_power_info( )
secs, pct: integer,
Rfr: SDL_GetPowerInfo.
-
{locale} = get_preferred_locales( )
Rfr: SDL_GetPreferredLocales.
-
path = get_base_path( )
path = get_pref_path(org, app)
org, app: string.
Rfr: SDL_GetBasePath, SDL_GetPrefPath.
Structs and data types
In this document, the float and integer types denote Lua numbers, while other types such as boolean, string, etc denote standard Lua types. Note that float here just means 'floating point' as opposed to 'integer', and does not imply single-precision.
Events returned by event handling functions and a few other structs used in the SDL2 C API are represented as string-indexed Lua tables, and are described in the subsections that follow.
point, rect, color
Points, rects, and colors are by default represented as Lua arrays containing float elements. The meaning of the elements thus depends on their position, as detailed below, and there is no syntactic sugar such as v.x and v.y to access them.
-
point = {x, y}
All elements are integers.
(Rfr: SDL_Point) -
fpoint = {x, y}
All elements are floats.
(Rfr: SDL_FPoint) -
rect = {x, y, w, h}
All elements are integers.
(Rfr: SDL_Rect) -
frect = {x, y, w, h}
All elements are floats.
(Rfr: SDL_FRect) -
color = {r, g, b, a}
All elements are integers (0..255).
(Rfr: SDL_Color) -
vertex = { position, color, texcoord }
position: fpoint,
color: color,
texcoord: fpoint (opt.).
(Rfr: SDL_Vertex)
memptr
A memptr object is a Lua light userdata representing a C pointer (void*) to a contiguous memory area of suitable size, where 'suitable' depends on the context. The size is not checked by MoonSDL2, thus beware of the potential dangers.
How such an object is accessed (or obtained, when passed as an argument) is not specified here. One may, for example, use hostmem objects from the MoonGLMATH library.
events
Rfr: SDL_Event.
An event is one of the structs described in this section, depending on the type field value (eventtype) as per the following list:
type: struct
'firstevent': commonevent,
'quit': commonevent,
'app terminating': commonevent,
'app lowmemory': commonevent,
'app willenterbackground': commonevent,
'app didenterbackground': commonevent,
'app willenterforeground': commonevent,
'app didenterforeground': commonevent,
'localechanged': commonevent,
'displayevent': displayevent,
'windowevent': windowevent,
'syswmevent': commonevent,
'keydown': keyboardevent,
'keyup': keyboardevent,
'textediting': texteditingevent,
'textinput': textinputevent,
'keymapchanged': commonevent,
'mousemotion': mousemotionevent,
'mousebuttondown': mousebuttonevent,
'mousebuttonup': mousebuttonevent,
'mousewheel': mousewheelevent,
'joyaxismotion': joyaxisevent,
'joyballmotion': joyballevent,
'joyhatmotion': joyhatevent,
'joybuttondown': joybuttonevent,
'joybuttonup': joybuttonevent,
'joydeviceadded': joydeviceaddedevent,
'joydeviceremoved': joydeviceremovedevent,
'joybatteryupdated': joybatteryevent,
'controlleraxismotion': controlleraxisevent,
'controllerbuttondown': controllerbuttonevent,
'controllerbuttonup': controllerbuttonevent,
'controllerdeviceadded': controllerdeviceaddedevent,
'controllerdeviceremoved': controllerdeviceevent,
'controllerdeviceremapped': controllerdeviceevent,
'controllertouchpaddown': controllertouchpadevent,
'controllertouchpadmotion': controllertouchpadevent,
'controllertouchpadup': controllertouchpadevent,
'controllersensorupdate': controllersensorevent,
'fingerdown': fingerevent,
'fingerup': fingerevent,
'fingermotion': fingerevent,
'dollargesture': dollargestureevent,
'dollarrecord': dollargestureevent,
'multigesture': multigestureevent,
'clipboardupdate': commonevent,
'dropfile': dropevent,
'droptext': dropevent,
'dropbegin': dropevent,
'dropcomplete': dropevent,
'audiodeviceadded': commonevent,
'audiodeviceremoved': commonevent,
'sensorupdate': sensorevent,
'render targets reset': commonevent,
'render device reset': commonevent,
'pollsentinel': commonevent,
'userevent': userevent,
'lastevent': commonevent.
-
commonevent = {
type: eventtype,
timestamp: integer (milliseconds),
} (rfr: SDL_Event) -
displayevent = {
type: 'displayevent',
timestamp: integer (milliseconds),
display: integer (1-based index),
event: displayeventtype,
data: integer,
} (rfr: SDL_DisplayEvent) -
windowevent = {
type: 'windowevent',
timestamp: integer (milliseconds),
window: window,
event: windoweventtype,
data1: integer,
data2: integer,
} (rfr: SDL_WindowEvent) -
keyboardevent = {
type: 'keydown' or 'keyup',
timestamp: integer (milliseconds),
window: window,
state: keystate,
repeat: boolean,
keycode: integer,
scancode: integer,
name: string (see SDL_Keycode)),
mod: keymod,
} (rfr: SDL_KeyboardEvent) -
texteditingevent = {
type: 'textediting',
timestamp: integer (milliseconds),
window: window,
text: string,
start: integer,
length: integer,
} (rfr: SDL_TextEditingEvent) -
textinputevent = {
type: 'textinput',
timestamp: integer (milliseconds),
window: window,
text: string,
} (rfr: SDL_TextInputEvent) -
mousemotionevent = {
type: 'mousemotion',
timestamp: integer (milliseconds),
window: window,
id: integer,
x: integer,
y: integer,
xrel: integer,
yrel: integer,
state: mousebuttonstate,
} (rfr: SDL_MouseMotionEvent) -
mousebuttonevent = {
type: 'mousebuttondown' or 'mousebuttonup',
timestamp: integer (milliseconds),
window: window,
id: integer,
x: integer,
y: integer,
button: button,
state: keystate,
clicks: integer,
} (rfr: SDL_MouseButtonEvent) -
mousewheelevent = {
type: 'mousewheel',
timestamp: integer (milliseconds),
window: window,
id: integer,
x: integer,
y: integer,
precise_x: float,
precise_y: float,
direction: mousewheeldir,
} (rfr: SDL_MouseWheelEvent) -
joyaxisevent = {
type: 'joyaxismotion',
timestamp: integer (milliseconds),
joystick: joystick,
id: integer,
axis: integer,
value: integer,
} (rfr: SDL_JoyAxisEvent) -
joyballevent = {
type: 'joyballmotion',
timestamp: integer (milliseconds),
joystick: joystick,
id: integer,
ball: integer,
xrel: integer,
yrel: integer,
} (rfr: SDL_JoyBallEvent) -
joyhatevent = {
type: 'joyhatmotion',
timestamp: integer (milliseconds),
joystick: joystick,
id: integer,
hat: integer,
value: hatstate,
} (rfr: SDL_JoyHatEvent) -
joybuttonevent = {
type: 'joybuttondown' or 'joybuttonup',
timestamp: integer (milliseconds),
joystick: joystick,
id: integer,
button: integer,
state: keystate,
} (rfr: SDL_JoyButtonEvent) -
joydeviceaddedevent = {
type: 'joydeviceadded',
timestamp: integer (milliseconds),
device_index: integer,
} (rfr: SDL_JoyDeviceEvent) -
joydeviceremovedevent = {
type: 'joydeviceremoved',
timestamp: integer (milliseconds),
joystick: joystick,
id: integer,
} (rfr: SDL_JoyDeviceEvent) -
joybatteryevent = {
type: 'joybatteryupdated',
timestamp: integer (milliseconds),
joystick: joystick,
id: integer,
level: joystickpowerlevel,
} (rfr: SDL_JoyBatteryEvent) -
controlleraxisevent = {
type: 'controlleraxismotion',
timestamp: integer (milliseconds),
controller: gamecontroller,
id: integer,
axis: controlleraxis,
value: integer,
} (rfr: SDL_ControllerAxisEvent) -
controllerbuttonevent = {
type: 'controllerbuttondown' or 'controllerbuttonup',
timestamp: integer (milliseconds),
controller: gamecontroller,
id: integer,
button: controllerbutton,
state: keystate,
} (rfr: SDL_ControllerButtonEvent) -
controllerdeviceaddedevent = {
type: 'controllerdeviceadded',
timestamp: integer (milliseconds),
device_index: integer,
} (rfr: SDL_ControllerDeviceEvent) -
controllerdeviceevent = {
type: 'controllerdeviceremoved' or 'controllerdeviceremapped',
timestamp: integer (milliseconds),
controller: gamecontroller,
id: integer,
} (rfr: SDL_ControllerDeviceEvent) -
controllertouchpadevent = {
type: 'controllertouchpaddown', 'controllertouchpadup', or 'controllertouchpadmotion',
timestamp: integer (milliseconds),
controller: gamecontroller,
id: integer,
touch_id: integer,
finger_id: integer,
x: float,
y: float,
pressure: float,
} (rfr: SDL_ControllerTouchpadEvent) -
controllersensorevent = {
type: 'controllersensorupdate',
timestamp: integer (milliseconds),
controller: gamecontroller,
id: integer,
sensor: sensortype data: {float}[3],
} (rfr: SDL_ControllerSensorEvent) -
fingerevent = {
type: 'fingerdown', 'fingerup', or 'fingermotion',
window: window,
timestamp: integer (milliseconds),
touch_id: integer,
finger_id: integer,
x: float,
y: float,
dx: float,
dy: float,
pressure: float,
} (rfr: SDL_TouchFingerEvent) -
dollargestureevent = {
type: 'dollargesture' or 'dollarrecord',
timestamp: integer (milliseconds),
touch_id: integer,
gesture_id: integer,
num_fingers: integer,
error: float,
x: float,
y: float,
} (rfr: SDL_DollarGestureEvent) -
multigestureevent = {
type: 'multigesture',
timestamp: integer (milliseconds),
touch_id: integer,
dtheta: float,
ddist: float,
x: float,
y: float,
num_fingers: integer,
} (rfr: SDL_MultiGestureEvent) -
dropevent = {
type: 'dropfile', 'droptext', 'dropbegin', or 'dropcomplete',
timestamp: integer (milliseconds),
file: string (pathname),
} (rfr: SDL_DropEvent) -
sensorevent = {
type: 'sensorupdate',
timestamp: integer (milliseconds),
sensor: sensor,
id: integer,
data: {float}[6],
} (rfr: SDL_SensorEvent) -
userevent = {
type: 'userevent',
timestamp: integer (milliseconds),
code: integer,
data: user defined Lua value,
} (rfr: SDL_UserEvent)
haptic effects
Rfr: SDL_HapticEffect.
An hapticeffect is one of the structs described in this section, depending on the type field value (haptictype) as per the following list:
type: struct
'constant': hapticconstant,
'sine': hapticperiodic,
'triangle': hapticperiodic,
'sawtoothup': hapticperiodic,
'sawtoothdown': hapticperiodic,
'leftright': hapticleftright,
'ramp': hapticramp,
'spring': hapticcondition,
'damper': hapticcondition,
'inertia': hapticcondition,
'friction': hapticcondition,
'custom': hapticcustom.
-
hapticconstant = {
type: 'constant',
dirtype: hapticdirection,
dir: {integer}[3],
length: integer,
delay: integer,
button: integer,
interval: integer,
level: integer,
attack_length: integer,
attack_level: integer,
fade_length: integer,
fade_level: integer,
} (rfr: SDL_HapticConstant) -
hapticperiodic = {
type: 'sine' or 'triangle' or 'sawtoothup' or 'sawtoothdown' ,
dirtype: hapticdirection,
dir: {integer}[3],
length: integer,
delay: integer,
button: integer,
interval: integer,
period: integer,
magnitude: integer,
offset: integer,
phase: integer,
attack_length: integer,
attack_level: integer,
fade_length: integer,
fade_level: integer,
} (rfr: SDL_HapticPeriodic) -
hapticcondition = {
type: 'spring' or 'damper' or 'inertia' or 'friction',
dirtype: hapticdirection,
dir: {integer}[3],
length: integer,
delay: integer,
button: integer,
inteval: integer,
right_sat: {integer}[3],
left_sat: {integer}[3],
right_coeff: {integer}[3],
left_coeff: {integer}[3],
deadband: {integer}[3],
center: {integer}[3],
} (rfr: SDL_HapticCondition) -
hapticramp = {
type: 'ramp',
dirtype: hapticdirection,
dir: {integer}[3],
length: integer,
delay: integer,
button: integer,
interval: integer,
start: integer,
end: integer,
attack_length: integer,
attack_level: integer,
fade_length: integer,
fade_level: integer,
} (rfr: SDL_HapticRamp) -
hapticleftright = {
type: 'leftright',
length: integer,
large_magnitude: integer,
small_magnitude: integer,
} (rfr: SDL_HapticLeftRight) -
hapticcustom = {
type: 'custom',
dirtype: hapticdirection,
dir: {integer}[3],
length: integer,
delay: integer,
button: integer,
interval: integer,
channels: integer,
period: integer,
samples: integer,
attack_length: integer,
attack_level: integer,
fade_length: integer,
fade_level: integer,
data: {integer}[samples*channels],
} (rfr: SDL_HapticCustom)
other structs
-
controllerbuttonbind =
{ type: 'none' } or
{ type: 'button', button: integer } or
{ type: 'axis', axis: integer } or
{ type: 'hat', hat: integer, mask: hatstate }
(rfr: SDL_GameControllerButtonBind) -
displaymode = {
format: pixelformat,
w: integer,
h: integer,
refresh_rate: integer,
driverdata: memptr,
} (rfr: SDL_DisplayMode) -
finger = {
finger_id: integer,
x: float,
y: float,
pressure: float,
} (rfr: SDL_Finger) -
hapticfeatures = {
constant: boolean,
sine: boolean,
leftright: boolean,
triangle: boolean,
sawtoothup: boolean,
sawtoothdown: boolean,
ramp: boolean,
spring: boolean,
damper: boolean,
inertia: boolean,
friction: boolean,
custom: boolean,
gain: boolean,
autocenter: boolean,
status: boolean,
pause: boolean,
} (rfr: SDL_HapticQuery) -
joystickguidinfo = {
vendor: integer,
product: integer,
version: integer,
crc16: integer,
} (rfr: SDL_GetJoystickGUIDInfo) -
keymod = {
lshift: boolean,
rshift: boolean,
shift: boolean,
lctrl: boolean,
rctrl: boolean,
ctrl: boolean,
lalt: boolean,
ralt: boolean,
alt: boolean,
lgui: boolean,
rgui: boolean,
gui: boolean,
num: boolean,
caps: boolean,
mode: boolean,
scroll: boolean,
none: boolean,
} (rfr: SDL_Keymod) -
locale = {
language: string,
country: string or nil,
} (rfr: SDL_GetPreferredLocales) -
messageboxbuttondata = {
flags: messageboxbuttonflags,
buttonid: integer,
text: string,
} (rfr: SDL_MessageBoxButtonData) -
messageboxdata = {
flags: messageboxflags,
window: window (opt.),
title: string,
message: string,
buttons: {messageboxbuttondata},
} (rfr: SDL_MessageBoxData) -
mousebuttonstate = {
left: boolean,
right: boolean,
middle: boolean,
x1: boolean,
x2: boolean,
} (rfr: SDL_GetMouseState) -
rendererinfo = {
name: string,
flags: rendererflags,
texture_formats: pixelformat,
max_texture_width: integer,
max_texture_height: integer,
} (rfr: SDL_RendererInfo) -
touchdevice = {
touch_id: integer,
name: string type: touchdevicetype,
num_fingers: integer,
} (rfr: SDL_GetTouchDevice)
Enums
SDL2 enums are mapped in MoonSDL2 to sets of string literals (as is customary in Lua). For example, the C enum SDL_LogPriority is mapped to the Lua enum type logpriority,
and the C value SDL_LOG_PRIORITY_XXX is mapped to the string literal 'xxx' (lowercase version of the XXX part of the C value name, with underscores replaced by spaces).
If needed, the following function can be used to obtain the list of literals admitted by a particular enum type:
-
{literal} = sdl.enum(enumtype)
Returns a table listing the literals admitted by enumtype (given as a string, e.g. 'hintpriority', 'logpriority', 'pixelformat' etc).
Below is the list of the enum types in MoonSDL2, together with their admitted literal values.
audioformat: AUDIO_XXX
Values: 'u8', 's8', 'u16', 's16', 'u16msb', 's16msb', 's32', 's32msb', 'f32', 'f32msb'.
blendfactor: SDL_BLENDFACTOR_XXX (SDL_BlendFactor)
Values: 'zero', 'one', 'src color', 'one minus src color', 'src alpha', 'one minus src alpha', 'dst color', 'one minus dst color', 'dst alpha', 'one minus dst alpha'.
blendoperation: SDL_BLENDOPERATION_XXX (SDL_BlendOperation)
Values: 'add', 'subtract', 'rev subtract', 'minimum', 'maximum'.
controlleraxis: SDL_CONTROLLER_AXIS_XXX (SDL_GameControlleAxis)
Values: 'invalid', 'leftx', 'lefty', 'rightx', 'righty', 'triggerleft', 'triggerright'.
controllerbindtype: SDL_CONTROLLER_BINDTYPE_XXX (SDL_GameControllerBindType)
Values: 'none', 'button', 'axis', 'hat'.
controllertype: SDL_CONTROLLER_TYPE_XXX (SDL_GameControllerType)
Values: 'unknown', 'xbox360', 'xboxone', 'ps3', 'ps4', 'nintendo switch pro', 'virtual', 'ps5', 'amazon luna', 'google stadia', 'nvidia shield', 'nintendo switch joycon left', 'nintendo switch joycon right', 'nintendo switch joycon pair'.
displayeventtype: SDL_DISPLAYEVENT_XXX (SDL_DisplayEventID)
Values: 'none', 'orientation', 'connected', 'disconnected'.
eventtype: SDL_XXX (SDL_EventType)
Values: 'firstevent', 'quit', 'app terminating', 'app lowmemory', 'app willenterbackground', 'app didenterbackground', 'app willenterforeground', 'app didenterforeground', 'localechanged', 'displayevent', 'windowevent', 'syswmevent', 'keydown', 'keyup', 'textediting', 'textinput', 'keymapchanged', 'mousemotion', 'mousebuttondown', 'mousebuttonup', 'mousewheel', 'joyaxismotion', 'joyballmotion', 'joyhatmotion', 'joybuttondown', 'joybuttonup', 'joydeviceadded', 'joydeviceremoved', 'joybatteryupdated', 'controlleraxismotion', 'controllerbuttondown', 'controllerbuttonup', 'controllerdeviceadded', 'controllerdeviceremoved', 'controllerdeviceremapped', 'controllertouchpaddown', 'controllertouchpadmotion', 'controllertouchpadup', 'controllersensorupdate', 'fingerdown', 'fingerup', 'fingermotion', 'dollargesture', 'dollarrecord', 'multigesture', 'clipboardupdate', 'dropfile', 'droptext', 'dropbegin', 'dropcomplete', 'audiodeviceadded', 'audiodeviceremoved', 'sensorupdate', 'render targets reset', 'render device reset', 'pollsentinel', 'userevent', 'lastevent'.
fading: MIX_XXX (Mix_Fading)
Values: 'no fading', 'fading out', 'fading in'.
flashoperation: SDL_FLASH_XXX (SDL_FlashOperation)
Values: 'cancel', 'briefly', 'until focused'.
fontalign: TTF_WRAPPED_ALIGN_XXX
Values: 'left', 'center', 'right'.
fontdirection: TTF_DIRECTION_XXX (TTF_Direction)
Values: 'ltr', 'rtl', 'ttb', 'btt'.
fonthinting: TTF_HINTING_XXX
Values: 'normal', 'light', 'mono', 'none', 'light subpixel'.
fullscreenmode
Values: 'real', 'fake', 'windowed'.
glattr: SDL_GL_XXX (SDL_GLattr)
Values: 'red size', 'green size', 'blue size', 'alpha size', 'buffer size', 'doublebuffer', 'depth size', 'stencil size', 'accum red size', 'accum green size', 'accum blue size', 'accum alpha size', 'stereo', 'multisamplebuffers', 'multisamplesamples', 'accelerated visual', 'retained backing', 'context major version', 'context minor version', 'context egl', 'context flags', 'context profile mask', 'share with current context', 'framebuffer srgb capable', 'context release behavior', 'context reset notification', 'context no error', 'floatbuffers'.
glprofile: SDL_GL_CONTEXT_PROFILE_XXX (SDL_GLprofile)
Values: 'core', 'compatibility', 'es'.
hapticdirection: SDL_HAPTIC_XXX
Values: 'polar', 'cartesian', 'spherical', 'steering axis'.
haptictype: SDL_HAPTIC_XXX
Values: 'constant', 'sine', 'leftright', 'triangle', 'sawtoothup', 'sawtoothdown', 'ramp', 'spring', 'damper', 'inertia', 'friction', 'custom'.
hatstate: SDL_HAT_XXX
Values: 'centered', 'up', 'right', 'down', 'left', 'rightup', 'rightdown', 'leftup', 'leftdown'.
hintpriority: SDL_HINT_XXX (SDL_HintPriority)
Values: 'default', 'normal', 'override'.
hittestresult: SDL_HITTEST_XXX (SDL_HitTestResult)
Values: 'normal', 'draggable', 'resize topleft', 'resize top', 'resize topright', 'resize right', 'resize bottomright', 'resize bottom', 'resize bottomleft', 'resize left'.
joystickpowerlevel: SDL_JOYSTICK_POWER_XXX (SDL_JoystickPowerLevel)
Values: 'unknown', 'empty', 'low', 'medium', 'full', 'wired'.
joysticktype: SDL_JOYSTICK_TYPE_XXX (SDL_JoystickType)
Values: 'unknown', 'gamecontroller', 'wheel', 'arcade stick', 'flight stick', 'dance pad', 'guitar', 'drum kit', 'arcade pad', 'throttle'.
keystate: SDL_XXX
Values: 'pressed', 'released'.
logcategory: SDL_LOG_CATEGORY_XXX (SDL_LogCategory)
Values: 'application', 'error', 'assert', 'system', 'audio', 'video', 'render', 'input', 'test'.
logpriority: SDL_LOG_PRIORITY_XXX (SDL_LogPriority)
Values: 'verbose', 'debug', 'info', 'warn', 'error', 'critical'.
mousewheeldir: SDL_MOUSEWHEEL_XXX (SDL_MouseWheelDirection)
Values: 'normal', 'flipped'.
musictype: MUS_XXX (Mix_MusicType)
Values: 'none', 'cmd', 'wav', 'mod', 'mid', 'ogg', 'mp3', 'flac', 'opus'.
orientation: SDL_ORIENTATION_XXX (SDL_DisplayOrientation)
Values: 'unknown', 'landscape', 'landscape flipped', 'portrait', 'portrait flipped'.
pixelformat: SDL_PIXELFORMAT_XXX (SDL_PixelFormatEnum)
Values: 'unknown', 'index1lsb', 'index1msb', 'index4lsb', 'index4msb', 'index8', 'rgb332', 'rgb444', 'bgr444', 'rgb555', 'bgr555', 'argb4444', 'rgba4444', 'abgr4444', 'bgra4444', 'argb1555', 'rgba5551', 'abgr1555', 'bgra5551', 'rgb565', 'bgr565', 'rgb24', 'bgr24', 'rgb888', 'rgbx8888', 'bgr888', 'bgrx8888', 'argb8888', 'rgba8888', 'abgr8888', 'bgra8888', 'argb2101010', 'yv12', 'iyuv', 'yuy2', 'uyvy', 'yvyu', 'nv12', 'nv21', 'external oes'.
powerstate: SDL_POWERSTATE_XXX (SDL_PowerState)
Values: 'unknown', 'on battery', 'no battery', 'charging', 'charged'.
rwopstype: SDL_RWOPS_XXX
Values: 'unknown', 'winfile', 'stdfile', 'jnifile', 'memory', 'memory ro'.
rwopswhence: RW_XXX
Values: 'seek set', 'seek cur', 'seek end'.
sensortype = SDL_SENSOR_XXX (SDL_SensorType)
Values: 'invalid', 'unknown', 'accel', 'gyro', or an integer for custom types.
scalemode: SDL_ScaleModeXXX (SDL_ScaleMode)
Values: 'nearest', 'linear', 'best'.
swapinterval
Values: 'immediate', 'vsync', 'adaptive vsync'.
systemcursor: SDL_SYSTEM_CURSOR_XXX (SDL_SystemCursor)
Values: 'arrow', 'ibeam', 'wait', 'crosshair', 'waitarrow', 'sizenwse', 'sizenesw', 'sizewe', 'sizens', 'sizeall', 'no', 'hand'.
textureaccess: SDL_TEXTUREACCESS_XXX (SDL_TextureAccess)
Values: 'static', 'streaming', 'target'.
touchdevicetype: SDL_TOUCH_DEVICE_XXX (SDL_TouchDeviceType)
Values: 'invalid', 'direct', 'indirect absolute', 'indirect relative'.
windoweventtype: SDL_WINDOWEVENT_XXX (SDL_WindowEventID)
Values: 'none', 'shown', 'hidden', 'exposed', 'moved', 'resized', 'size changed', 'minimized', 'maximized', 'restored', 'enter', 'leave', 'focus gained', 'focus lost', 'close', 'take focus', 'hit test', 'iccprof changed', 'display changed'.
Flags
Flags in MoonSDL2 functions and structs are always represented as plain integers, and encoded in the same way as the corresponding flags in the C SDL2 API.
The sdl table contains the SDL_XXX values, renamed as sdl.XXX (e.g. sdl.INIT_TIMER, sdl.INIT_AUDIO, etc.). It also contains the IMG_XXX values from SDL2_image renamed as sdl.IMG_XXX, and similarly for the values from SDL2_ttf and SDL2_mixer.
For each flags type (see the list below), a utility function is also available to map an integer code to a list of string literals, each corresponding to an individual bit set in the code, and viceversa to encode an integer value from the individual bits given as a list of string literals. The generic definition of such functions is the following, where xxxflags stands for initflags, windowflags, etc:
-
code = xxxflags(s1, s2, …)
s1, s2, … = xxxflags(code)
Maps the integer code to/from the list of string values s1, s2, ….
audioallowflags: sdl.AUDIO_ALLOW_XXX
Values: 'frequency change', 'format change', 'channels change', 'samples change', 'any change'.
flipflags: sdl.FLIP_XXX (SDL_RendererFlip)
Values: 'none', 'horizontal', 'vertical'.
glcontextflags: sdl.SDL_GL_CONTEXT_XXX_FLAG (SDL_GLcontextFlag)
Values: 'debug', 'forward compatible', 'robust access', 'reset isolation'.
imginitflags: sdl.IMG_INIT_XXX (IMG_InitFlags)
Values: 'jpg', 'png', 'tif', 'webp', 'jxl', 'avif'.
initflags: sdl.INIT_XXX
Values: 'timer', 'audio', 'video', 'joystick', 'haptic', 'gamecontroller', 'events', 'sensor', 'noparachute', 'everything'.
messageboxflags: sdl.MESSAGEBOX_XXX (SDL_MessageBoxFlags)
Values: 'error', 'warning', 'information', 'buttons left to right', 'buttons right to left'.
mixinitflags: sdl.MIX_INIT_XXX (MIX_InitFlags)
Values: 'flac', 'mod', 'mp3', 'ogg', 'mid', 'opus'.
rendererflags: sdl.RENDERER_XXX (SDL_RendererFlags)
Values: 'software', 'accelerated', 'presentvsync', 'targettexture'.
ttfstyleflags: sdl.TTF_STYLE_XXX
Values: 'normal', 'bold', 'italic', 'underline', 'strikethrough'.
windowflags: sdl.WINDOW_XXX (SDL_WindowFlags)
Values: 'fullscreen', 'opengl', 'shown', 'hidden', 'borderless', 'resizable', 'minimized', 'maximized', 'mouse grabbed', 'input focus', 'mouse focus', 'fullscreen desktop', 'foreign', 'allow highdpi', 'mouse capture', 'always on top', 'skip taskbar', 'utility', 'tooltip', 'popup menu', 'keyboard grabbed', 'vulkan', 'metal', 'input grabbed'.