lua-users home
lua-l archive

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


Brad Olson wrote:
> Did I assume right about what can
> and cannot be copied?

Some more remarks to add to those of BSH and LHF:

-  Lua functions are _mutable_ objects (their environment can be changed)
but I can't think of a way to make a copy of one.  So that's a real problem.

-  Copying a table should at least take its metatable into account.  Whether
or not you should deep-copy the metatable will depend on the application you
have in mind I guess.  If the metatable is protected then this is another
no-go...

-  It seems fair to deep-copy a table's _keys_ as well as its values.

-  For each original object, exactly one deep-copied object should be
produced.  (This extends the "cyclic tables" issue mentioned by BSH.)

Bye,
Wim