Clone vs Copy - any libs for that?
I ran into the small issues that tables are generally handed to and from function by reference instead of by value. So I need to channel my inner mad scientist and start cloning.
Some search gave me these code for shallow and deep cloning respectively: Code:
function copy (t) -- shallow-copy a table Code:
function clone (t) -- deep-copy a table And of course it could help to fold both functions into one with a bool switch/int to tell the maximum depth to clone. Has annybody already written some code for cloning in his library so I don't repeat the same code? |
This already exists as a global function implemented by ZO:
lua Code:
This excludes metatables, however, and at a glance, it looks like it will crash on any circular reference. |
Quote:
|
I used the following in GuildLib
lua Code:
It kept a list of table references in the external local, and just copied the reference if it had already been traversed. |
All times are GMT -6. The time now is 09:08 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI