Skip to content

Tutorial 01 Initialization

Tipudev edited this page Sep 29, 2025 · 2 revisions

Tutorial 01 - Initialization

In this tutorial, we will load and initialize SDL.

Full example: 01-initialization.tgz

Loading the module

To load the module, call the require function. This only loads the module, it does not initialize the library. However, if some internal code fails, a Lua error will be raised.

local SDL = require("SDL")

Obviously, you can use a different table name.

Note: Lua-SDL2 does not set any globals.

Initialize the library

The library must be now initialized with SDL.init, passing a list of SDL.flags. In our example, we want to load the video and audio subsystem.

assert(SDL.init{
    SDL.flags.Video,
    SDL.flags.Audio,
})

Showing the version

Now that we have loaded the library, show the version implemented. This is the SDL version, not Lua-SDL version.

-- Show the version
print(string.format("SDL %d.%d.%d",
    SDL.VERSION_MAJOR,
    SDL.VERSION_MINOR,
    SDL.VERSION_PATCH
))

Quit

When you're done, call SDL.quit

SDL.quit()

Clone this wiki locally