On 16 September 2014 13:00, Roman Tsisyk <roman@xxxxxxxxxxxxx> wrote: > 2. Specialized versions for particular sizes - do compile, but looks ugly > > local function unpack3(t) > if #t == 1 then > return t[1] > else if #t == 2 then > return t[1], t[2] > else if #t == 3 then > return t[1], t[2], t[3] > else > return unpack(t) -- goodbye, JIT > end > end It doesn't have to be that ugly. The following is more or less equivalent: local function unpack3(t) if #t <= 3 then return t[1], t[2], t[3] else return unpack(t) end end You could also make an unpack5 without any extra redundant branches or length operators and only a little extra code.