lua-users home
lua-l archive

Re: Moving key & values from one table to another

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


Well, I got that in the meantime, thanks... :-)
Ashwin Hirschi wrote:
Are there any tricks to insert all the keys and values of one table into
another?
function dup(tab)
 local res = {}
 if type(tab) ~= "table" then return tab end
 for k, v in tab do res[dup(k)] = dup(v) end
 return res
end
And it's kind of safe too :)
Eh... kind-of-safe as in "only returns with a stack overflow" from:
 a = {}
 a.b = a
 dup(a)
you mean? [;-)]
Ashwin.
--
Hercinger Viktor
0x2b || !0x2b

AltStyle によって変換されたページ (->オリジナル) /