-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add table.copy_with_metatables
#15754
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good aside from some minor things.
(Edit: For some reason Github seems to show batched follow-up comments without much context on previous posts.)
This comment was marked as outdated.
This comment was marked as outdated.
doc/lua_api.md
Outdated
* returns a deep copy of `table` | ||
* since 5.12: | ||
* `table` can also be non-table value, which will be returned as-is. | ||
* `preserve_metatables`: whether to preserve metatables as they are, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might need another remark:
Due to implementation details, specifying `preserve_metatables` on engine versions
without `core.features.table_copy_preserve_metatables` is likely to cause errors.
I think I will turn this into
|
table.copy
to preserve metatablestable.copy_with_metatables
@@ -4142,6 +4142,11 @@ Helper functions | |||
* returns time with microsecond precision. May not return wall time. | |||
* `table.copy(table)`: returns a table | |||
* returns a deep copy of `table` | |||
* strips metatables, but this may change in the future |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO we don't need the metatable-related behavior to change in the future since we have table.copy_with_metatable()
as a separate function now.
shorter name suggestion: |
Wouldn't be better to have a boolean as an extra parameter in the original table.copy? |
The issue is that (Adding the option as a third parameter would be doable, but it is IMO annoying since the second parameter would almost alwasy be |
I'd support metacopy. It makes sense and if anyone is confused, docs are there. |
Implements what I have suggested in #15744.
How to test
There are basic unit tests. Feel free to add more.