lua-users home
lua-l archive

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


On Apr 5, 2014, at 9:57 AM, Rena <hyperhacker@gmail.com> wrote:
> 
> * It can copy any type except for Userdata (unless it has __xcopy) and Thread (as that makes
>   no sense really). String copying is binary-safe (but maybe not terribly memory-efficient, since
>   each Lua state will internally make a copy of the string). Tables are copied recursively (but
>   there's nothing to prevent infinite recursion, so be careful of nested references). Functions can
>   be copied, but they might not work as expected due to a lack of _ENV (this is something I
>   still need to investigate and fix).
> 

Be careful about table copying. Apart from the obvious issues with cyclical table references, you also need to deal with multiple references to the same table:

t = {}
x = {}
t.a = x
t.b = x

In our table persist algorithm we handle all these cases but it requires quite a bit of juggling to make sure the end result is correct (we actually emit Lua source code that rebuilds the table).

—Tim