Corona SDK Pro Tip of the Day #9
Params table

Use params table for functions that accept many arguments, especially if some of these arguments are optional.

If you remember some time ago Corona Labs changed syntax for display.newText() function. Because it had many arguments, they converted it to accept params table instead.

With params table Lua gives us what is called in other languages as "named arguments."

I always emphasis how code readability is important. So just compare the two forms.

display.newText(self.view, 'Some Text Here', 200, 100, 300, 20, native.systemFont, 20)  
    parent = self.view,
    text = 'Some Text Here',
    x = 200, y = 100,
    width = 300, height = 20,
    font = native.systemFont,
    fontSize = 20}

Notice that when using such syntax you don't need round parenthesis.

Using params I can rewrite a function from my previous Pro Tip.

local function newCoin(params)  
    params = params or {}  
    local coin = {}
    coin.value = params.value or 1
    coin.color = params.color or 'gold'
    coin.size = params.size or 32
    return coin

Indie Game Developer