[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Moving key & values from one table to another
- From: "nvleer" <nvleer@...>
- Date: Wed, 1 Mar 2006 16:59:54 -0500 (EST)
> 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