From 670a86c74bc356fe72a0388c0543d077c48b43fb Mon Sep 17 00:00:00 2001 From: Citrine Date: Tue, 19 Mar 2024 16:48:35 -0700 Subject: [PATCH] refactor(tablefunctions): make copy and invert functions, not methods (#2726) These methods can never actually be used as methods, because tables do not automatically share a metatable like classes do. Thus `tbl:copy()` does not know to look in `table` to find `copy()`. This commit doesn't actually change any functionality, it just makes it clearer how to use the functions. --- common/tablefunctions.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/common/tablefunctions.lua b/common/tablefunctions.lua index 71ccf39a00d..5fa29b5b55d 100644 --- a/common/tablefunctions.lua +++ b/common/tablefunctions.lua @@ -6,9 +6,9 @@ run for end users.) ]] if not table.copy then - function table:copy() + function table.copy(tbl) local copy = {} - for key, value in pairs(self) do + for key, value in pairs(tbl) do if type(value) == "table" then copy[key] = table.copy(value) else @@ -99,9 +99,9 @@ if not table.toString then end if not table.invert then - function table:invert() + function table.invert(tbl) local inverted = {} - for key, value in pairs(self) do + for key, value in pairs(tbl) do inverted[value] = key end return inverted