garrysmod icon indicating copy to clipboard operation
garrysmod copied to clipboard

Enhance table.Copy

Open Zaurzo opened this issue 1 year ago • 7 comments

Changes

Added Arguments copyVecAngMx - Will make the function copy Vector, Angle, and VMatrix objects. noMeta- Will not set the metatable of the given table to the copy result, if there is one.

Additional Changes The function will yield an error if the first argument isn't a table. The function now only sets the metatable of the given table to the copy result after everything has been copied. Updated the command description in the comment above it.

There is some changes I want to discuss in this PR, however:

  1. Is making the function error a bad idea? Will it break some addons?

  2. Will making the function set the metatable to the copy after it's done copying cause issues?

  • I made this change because a table I was trying to copy had its own __newindex behavior, and since the original function set the metatable before it added all of the values, it caused some problems.
  1. Should the copyVecAngMx argument even exist, or should I make it always copy Vector, Angle, and VMatrix objects?

  2. Is the backwards compatibility for the lookup_table argument even necessary?

I am looking forward to reading the thoughts on this. Thanks

Zaurzo avatar Dec 09 '23 15:12 Zaurzo