lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 2/23/06, Gavin Kistner <gavin@refinery.com> wrote:
Not directly, no. Yes, I can grab 'a', and 'b' directly, but I can't use the (unknown) number of later values unless I shift the table down.

local results = { func() }
local a = table.remove( results, 1 )
local b = table.remove( results, 1 )
return 'x', unpack( results )

I had been assuming that I should avoid doing this. I thought that shifting the entire table down was relatively slow. Does Lua perform some nice internal magic on the internal array half of the table, just shifting the start pointer up?

You would have to test and benchmark for your specific situation.  The overhead isn't that much depending on how often you are doing this and how many results are in the table.  You could also return a and b as the last entries rather than the first for a little speedup if you have a lot of entries.

Of course, why even remove the first two from the results table?  At some point something is working with the other values and it can just skip the first two.