stetre / moonsdl2

Lua bindings for SDL2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Window closes ~10 seconds after program execution

Swift-mamba opened this issue · comments

Im using the example with lua 5.4 and I'm on windows

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
	  print(e[item])
      if e.type == 'quit' then quit = false end
   end
   renderer:set_draw_color({0, 0, 0, 255})
   renderer:clear()
   renderer:render_geometry(nil, vertices, nil)
   renderer:present()
end

Does it print anything on stdout when closing?

By the way, print(e[item]) seems wrong to me, since item is an undeclared variable so its value is nil. Besides, the event table has no field named item. Try replacing it with either print(e.type) or print(e['type']) .

thanks