-
Notifications
You must be signed in to change notification settings - Fork 74
Tutorial 01 Initialization
Tipudev edited this page Sep 29, 2025
·
2 revisions
In this tutorial, we will load and initialize SDL.
Full example: 01-initialization.tgz
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.
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,
})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
))When you're done, call SDL.quit
SDL.quit()