summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kolesa <quaker66@gmail.com>2014-02-04 15:33:36 +0000
committerDaniel Kolesa <quaker66@gmail.com>2014-02-04 15:33:36 +0000
commitc67d93cf9dff38927e13e87adee74568608717c0 (patch)
treec202e46f8b62a4ed3df0fbfb720358bf35cfd329
parent67a65d3734949e4c30dc4940783d3e8dbbad3f75 (diff)
get rid of inner loops inside engines - tail recursion instead
-rw-r--r--engine_sw_sdl.lua10
-rw-r--r--engine_x11.lua17
2 files changed, 11 insertions, 16 deletions
diff --git a/engine_sw_sdl.lua b/engine_sw_sdl.lua
index 0139140..6fcfc84 100644
--- a/engine_sw_sdl.lua
+++ b/engine_sw_sdl.lua
@@ -550,11 +550,11 @@ local evtypes = {
550} 550}
551 551
552local ev = ffi.new("SDL_Event") 552local ev = ffi.new("SDL_Event")
553local engine_sdl_loop = function() 553local engine_sdl_loop; engine_sdl_loop = function()
554 while lsdl.SDL_PollEvent(ev) ~= 0 do 554 if lsdl.SDL_PollEvent(ev) == 0 then return end
555 local f = evtypes[ev.type] 555 local f = evtypes[ev.type]
556 if f then f(ev) end 556 if f then f(ev) end
557 end 557 return engine_sdl_loop()
558end 558end
559 559
560local engine_sdl_shutdown = function() 560local engine_sdl_shutdown = function()
diff --git a/engine_x11.lua b/engine_x11.lua
index 18bb6d7..7f9076f 100644
--- a/engine_x11.lua
+++ b/engine_x11.lua
@@ -519,15 +519,12 @@ local evtypes = {
519 519
520local ev = ffi.new("XEvent") 520local ev = ffi.new("XEvent")
521engine_x11_loop = function() 521engine_x11_loop = function()
522 while true do 522 if xlib.XCheckMaskEvent(disp, bor(lsh(1, 15), lsh(1, 2), lsh(1, 3),
523 if xlib.XCheckMaskEvent(disp, bor(lsh(1, 15), lsh(1, 2), lsh(1, 3), 523 lsh(1, 6), lsh(1, 17), lsh(1, 4), lsh(1, 5), lsh(1, 0), lsh(1, 1)),
524 lsh(1, 6), lsh(1, 17), lsh(1, 4), lsh(1, 5), lsh(1, 0), lsh(1, 1)), 524 ev) == 0 then return end
525 ev) == 0 then 525 local evf = evtypes[ev.type]
526 return 526 if evf then evf(ev) end
527 end 527 return engine_x11_loop()
528 local evf = evtypes[ev.type]
529 if evf then evf(ev) end
530 end
531end 528end
532 529
533local engine_x11_shutdown = function() 530local engine_x11_shutdown = function()
@@ -535,8 +532,6 @@ local engine_x11_shutdown = function()
535 xlib.XCloseDisplay(disp) 532 xlib.XCloseDisplay(disp)
536end 533end
537 534
538
539
540return { init = function(engines, rmth) 535return { init = function(engines, rmth)
541 engines[#engines + 1] = { 536 engines[#engines + 1] = {
542 engine_sname[rmth], 537 engine_sname[rmth],