From 9bcb4285556879861e33497841133e1b34c518b2 Mon Sep 17 00:00:00 2001 From: Matthias Richter Date: Wed, 19 Jan 2011 16:41:59 +0100 Subject: [PATCH] Make proper tail recursion calls --- gamestate.lua | 18 +++++++++--------- timer.lua | 5 ++--- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/gamestate.lua b/gamestate.lua index 3cc8523..aa0205e 100644 --- a/gamestate.lua +++ b/gamestate.lua @@ -63,55 +63,55 @@ function switch(to, ...) current:leave() local pre = current current = to - current:enter(pre, ...) + return current:enter(pre, ...) end local _update function update(...) if _update then _update(...) end - current:update(...) + return current:update(...) end local _draw function draw(...) if _draw then _draw(...) end - current:draw(...) + return current:draw(...) end local _keypressed function keypressed(...) if _keypressed then _keypressed(...) end - current:keypressed(...) + return current:keypressed(...) end local _keyreleased function keyreleased(...) if _keyreleased then _keyreleased(...) end - current:keyreleased(...) + return current:keyreleased(...) end local _mousepressed function mousepressed(...) if _mousereleased then _mousepressed(...) end - current:mousepressed(...) + return current:mousepressed(...) end local _mousereleased function mousereleased(...) if _mousereleased then _mousereleased(...) end - current:mousereleased(...) + return current:mousereleased(...) end local _joystickpressed function joystickpressed(...) if _joystickpressed then _joystickpressed(...) end - current:joystickpressed(...) + return current:joystickpressed(...) end local _joystickreleased function joystickreleased(...) if _joystickreleased then _joystickreleased(...) end - current:joystickreleased(...) + return current:joystickreleased(...) end function registerEvents() diff --git a/timer.lua b/timer.lua index 8a771a6..7e602ee 100644 --- a/timer.lua +++ b/timer.lua @@ -54,10 +54,9 @@ end function addPeriodic(delay, func, count) assert(type(func) == "function", "second argument needs to be a function") if count then - add(delay, function(f) func(func) count = count - 1 if count > 0 then add(delay, f) end end) - else - add(delay, function(f) func(func) add(delay, f) end) + return add(delay, function(f) func(func) count = count - 1 if count > 0 then add(delay, f) end end) end + return add(delay, function(f) func(func) add(delay, f) end) end function clear()