stetre / moonsdl2

Lua bindings for SDL2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MoonSDL2: Lua bindings for SDL2

MoonSDL2 is a Lua binding library for the Simple DirectMedia Layer (SDL2).

It runs on GNU/Linux and on Windows (MSYS2/MinGW) and requires Lua (>=5.3), SDL2 (>= 2.26.0), SDL_image (>= 2.6.3), SDL_mixer (>= 2.6.0), and SDL_ttf (>= 2.20.0).

Author: Stefano Trettel

Lua logo

License

MIT/X11 license (same as Lua). See LICENSE.

Documentation

See the Reference Manual.

Getting and installing

Setup the build environment as described here, then:

$ git clone https://github.com/stetre/moonsdl2/
$ cd moonsdl2
moonsdl2$ make
moonsdl2$ sudo make install

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.

-- 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:

$ lua hello.lua

See also

About

Lua bindings for SDL2

License:Other


Languages

Language:C 99.5%Language:Makefile 0.5%