lua-users home
lua-l archive

Re: copy a table

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


Thomas Hafner <thomas@hafner.NL.EU.ORG> wrote/schrieb <7ms094-257.ln1@faun.hafner.nl.eu.org>:
> what's the easiest way to copy a given table?
I think I've found it, see below.
> If variable ``source'' references the table, just the assignment
> target = source
> won't do it: no new table will be constructed, but ``target'' will
> reference the same table as ``source'' (e.g. after the assignment
> target[1]=42, source[1] will be set to 42, too).
This will do it:
 target = {unpack(source)}
(It's neither flat-copy nor deep-copy; it's somehow
level-1-deep-copy.)
Regards
 Thomas

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