Corona SDK Pro Tip of the Day #32
Table instead of "if else" wall

Lua language lacks a switch statement. Instead we use a wall of if ... elseif ... elseif ... statements.

However it may be not the most efficient or prettier way. There is a great page listing alternative approaches, how to code something similar to the switch statement.

http://lua-users.org/wiki/SwitchStatement

Using tables to store different actions as functions instead of if ... else statements is generally a good idea.

local actions = {}  
actions.in = function(obj)  
    obj.alpha = 0
    transition.to(obj, {time = 1000, alpha = 1})
end  
actions.out = function(obj)  
    obj.alpha = 1
    transition.to(obj, {time = 1000, alpha = 0})
end  
actions.inout = function(obj)  
    obj.alpha = 0
    transition.to(obj, {time = 1000, alpha = 1, onComplete = actions.out})
end

local function fade(obj, how)  
    actions[how](obj)
end

fade(circle, 'inout')  

Indie Game Developer