lua-users home
lua-l archive

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

Quoth Axel Kittenberger <>, on 2011-01-10 00:04:44 +0100:
> Proposal a function table.icopy(table, src, dest, n) which replaces
> the need for insert and remove.
> It copies n integer keys from src to dest. Its inspired by ECMA's
> splice, and for those with C background to behave more like memmove()
> to defined when src and destination slice overlap.

FWIW, I have almost exactly this function in a program of mine, except
I call it _blit, and it has a different signature:

  function _blit(dst, dst_first, src, src_first, count)
     src_first = src_first or 1
     local offset = dst_first - src_first
     local src_last = #src
     if count then src_last = src_first + count - 1 end
     for i = src_first, src_last do dst[i+offset] = src[i] end
     return dst

And then I can do things like:

  function _appendn(dst, src)
    return _blit(dst, #dst+1, src, 1, #src)

(These are slightly translated from the original form.)

   ---> Drake Wilson