Skip to content

When an why should lua objects be cloned? #9509

Answered by tarleb
CodeSandwich asked this question in Q&A
Discussion options

You must be logged in to vote

That's a good question.

Is header.attr = otherHeader.attr safe?

No.

Is pandoc.Header(1, "header", otherHeader.attr) safe?

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. The walk{} hack mentioned above is a good way to ensure a deep copy.

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@CodeSandwich
Comment options

@tarleb
Comment options

@tarleb
Comment options

Answer selected by CodeSandwich
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants