lua-users home
lua-l archive

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


> Are there any tricks to insert all the keys and values 
> of one table into another?
> I know you can't use unpack except on numbered index values.   
> Is my only choice a table.foreach with an insert of each value 
> from `t' into `u'?

Its better to loop over the table using pairs().  Its a bit faster (about 20%) and [unfortunately] table.foreach is deprecated as of 5.1.  This is what I had:

   function clone(t)
      local u = {}
      for k,v in pairs(t) do u[k] = v end
      return u
   end

_______________________________________________
No banners. No pop-ups. No kidding.
Make My Way  your home on the Web - http://www.myway.com