Avoid "unpack()"

Hi,

I saw on this link that i should avoid unpack().

http://docs.coronalabs.com/guide/basics/optimization/index.html

here is my Example code:

local opts = {

“image01.jpg”,100,300

}

local function returnArgs(opt)

    local vars = “”

    local op = “”

    for i = 1,#opt do

        vars = vars…opt[i]…"," 

        op = op… “([^,]+)”…","

    end

    return  vars:match(op)

end

print(unpack(opts))

–display.newImage(returnArgs(opts))

–display.newImage(unpack(opts))

this code allow me to use a table as an argument of any API.

Is it better to use unpack or this other function?

How bad is to use Unpack?

Is there any other solution to return ther arguments of a function?
 

Thank you very much.

Unless you are going to call unpack several hundred times in a loop in a single frame, or in every frame of an enterframe listener, I don’t think it is going to make much of a difference. 

If you only going to call unpack occasionally, I’d suggest you just use it. 

 

Hi @2creativegames,

Satheesh is correct… unpack() should primarily be avoided in big loops or on a massively huge table during time-critical points. If you’re just using it casually once or twice, go ahead.

Brent

Unless you are going to call unpack several hundred times in a loop in a single frame, or in every frame of an enterframe listener, I don’t think it is going to make much of a difference. 

If you only going to call unpack occasionally, I’d suggest you just use it. 

 

Hi @2creativegames,

Satheesh is correct… unpack() should primarily be avoided in big loops or on a massively huge table during time-critical points. If you’re just using it casually once or twice, go ahead.

Brent