When an why should lua objects be cloned? #9509
-
Each lua object has the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
`walk()` should be used with an empty filter instead of `clone()` when you want to perform a deep copy of an object, i. e. one where all members of the object are copied too and where a modification to the source object doesn't entail one to the new object. To the contrary, with `header.attr = otherHeader.attr` or `header.attr = otherHeader.attr:clone()`, `header.attr` becomes a mere pointer to `otherHeader.attr`.
|
Beta Was this translation helpful? Give feedback.
-
That's a good question.
No.
Yes. In general, calls to a constructor function will deep-clone the arguments. The one exception to this are lists, i.e. |
Beta Was this translation helpful? Give feedback.
That's a good question.
No.
Yes.
In general, calls to a constructor function will deep-clone the arguments. The one exception to this are lists, i.e.
pandoc.List
. The behavior of lists can, admittedly, be a bit unexpected at times. Thewalk{}
hack mentioned above is a good way to ensure a deep copy.