lua-users home
lua-l archive

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


On Wed, Sep 26, 2018 at 3:20 PM, Dirk Laurie wrote:

table.clear = function(tbl)
   local n=#tbl
   table.move(tbl,n+1,2*n,1)
end


Negative indices don't have "backwards" meaning in table.move(), so we can write more compact code

table.clear = function(tbl)
  table.move(tbl, -#tbl, -1, 1)
end