https://github.com/stetre/moonsdl2
Lua bindings for SDL2
https://github.com/stetre/moonsdl2
lua-bindings sdl2
Last synced: about 1 month ago
JSON representation
Lua bindings for SDL2
- Host: GitHub
- URL: https://github.com/stetre/moonsdl2
- Owner: stetre
- License: other
- Created: 2023-05-19T10:48:21.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2024-11-11T11:42:40.000Z (over 1 year ago)
- Last Synced: 2024-11-11T12:33:14.391Z (over 1 year ago)
- Topics: lua-bindings, sdl2
- Language: C
- Homepage:
- Size: 1.21 MB
- Stars: 5
- Watchers: 1
- Forks: 2
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## MoonSDL2: Lua bindings for SDL2
MoonSDL2 is a Lua binding library for the [Simple DirectMedia Layer (SDL2)](https://www.libsdl.org).
It runs on GNU/Linux and on Windows (MSYS2/MinGW or MSVC) and requires
[Lua](http://www.lua.org/) (>=5.3),
[SDL2](https://github.com/libsdl-org/SDL/releases/) (>= 2.26.0),
[SDL_image](https://github.com/libsdl-org/SDL_image/releases/) (>= 2.6.3),
[SDL_mixer](https://github.com/libsdl-org/SDL_mixer/releases/) (>= 2.6.0), and
[SDL_ttf](https://github.com/libsdl-org/SDL_ttf/releases/) (>= 2.20.0).
_Author:_ _[Stefano Trettel](https://www.linkedin.com/in/stetre)_
[](http://www.lua.org/)
#### License
MIT/X11 license (same as Lua). See [LICENSE](./LICENSE).
#### Documentation
See the [Reference Manual](https://stetre.github.io/moonsdl2/doc/index.html).
#### Getting and installing
Setup the build environment as described [here](https://github.com/stetre/moonlibs), then:
```sh
$ git clone https://github.com/stetre/moonsdl2/
$ cd moonsdl2
moonsdl2$ make
moonsdl2$ sudo make install
```
**On Windows Using Visual Studio**
```
> git clone https://github.com/stetre/moonsdl2/
> cd moonsdl2\src
> mingw32-make -f Makefile.msvc ^
LUAVER= ^
LUA_INCDIR= ^
LUA_LIBDIR= ^
SDL_INCDIR= ^
SDL_LIBDIR=
```
`` is in dotted notation, like "5.1" (no quotes).
Ensure all the other directories don't have spaces in their paths.
If you don't have access to `mingw32-make`, you can edit `src\rebuild.bat` to
suit your Lua version and paths, and then run it (from the `src` directory) to
perform a full rebuild.
#### Example
The example below creates a window and draws a triangle using SDL2's 2D renderer.
Other examples can be found in the **examples/** directory contained in the release package.
```lua
-- MoonSDL2 example: hello.lua
local sdl = require("moonsdl2")
sdl.init()
local window = sdl.create_window("Hello, triangle!", nil, nil, 800, 600, sdl.WINDOW_SHOWN)
local renderer = sdl.create_renderer(window, nil, sdl.RENDERER_ACCELERATED|sdl.RENDERER_PRESENTVSYNC)
local vertices =
{ -- position color
{ { 400, 150 }, { 255, 0, 0, 255 } },
{ { 200, 450 }, { 0, 0, 255, 255 } },
{ { 600, 450 }, { 0, 255, 0, 255 } },
}
local quit = false
while not quit do
e = sdl.poll_event()
if e then
if e.type == 'quit' then quit = true end
end
renderer:set_draw_color({0, 0, 0, 255})
renderer:clear()
renderer:render_geometry(nil, vertices, nil)
renderer:present()
end
```
The script can be executed at the shell prompt with the standard Lua interpreter:
```shell
$ lua hello.lua
```
#### See also
* [MoonLibs - Graphics and Audio Lua Libraries](https://github.com/stetre/moonlibs).