mirror of
https://github.com/luau-lang/rfcs.git
synced 2025-04-19 03:13:49 +01:00
Allow table.clone
to copy tables with locked metatables
This commit is contained in:
parent
03608c7519
commit
a1583ce972
1 changed files with 21 additions and 0 deletions
21
table.clone-locked-metatables.md
Normal file
21
table.clone-locked-metatables.md
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
# Feature name
|
||||||
|
|
||||||
|
## Summary
|
||||||
|
|
||||||
|
Allow `table.clone` to copy tables with locked metatables.
|
||||||
|
|
||||||
|
## Motivation
|
||||||
|
|
||||||
|
Currently `table.clone` cannot create shallow copies of a table if it has a locked metatable. The dictionary definition for shallow copying is to copy all the fields of a table to a new table but not doing so recursively. There is no mention of metatables in the first place so most users expect said behavior just to work, if they haven't taken a look at the manual of course.
|
||||||
|
|
||||||
|
## Design
|
||||||
|
|
||||||
|
When `table.clone` attempts to clone a table with a locked metatable the table is shallow copied with the exception of not assigning the metatable to the shallow copy.
|
||||||
|
|
||||||
|
## Drawbacks
|
||||||
|
|
||||||
|
There are no drawbacks to this. You can already create a shallow copy of a table with a locked metatable (without assigning the metatable to the copy) so there is no downside in allowing `table.clone` to do the same.
|
||||||
|
|
||||||
|
## Alternatives
|
||||||
|
|
||||||
|
An alternate mode of action would be to also clone the locked metatable to the new copy. This would however come with a few downsides including potential security and usability issues.
|
Loading…
Add table
Reference in a new issue