From 8af94a7194d58a07b999c82dd7ca346e65263773 Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Sun, 26 Jan 2025 04:05:29 +1100 Subject: [PATCH] feat(class): allow private to be redefined Allows self.private to defined as a new table, allowing it to remain empty without being removed after instantiation. Resolves #696. --- imports/class/shared.lua | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/imports/class/shared.lua b/imports/class/shared.lua index bf91125..a089df0 100644 --- a/imports/class/shared.lua +++ b/imports/class/shared.lua @@ -55,10 +55,8 @@ local function void() return '' end ---@return T function mixins.new(class, ...) local constructor = getConstructor(class) - - local obj = setmetatable({ - private = {} - }, class) + local private = {} + local obj = setmetatable({ private = private }, class) if constructor then local parent = class @@ -75,8 +73,8 @@ function mixins.new(class, ...) rawset(obj, 'super', nil) - if next(obj.private) then - local private = table.clone(obj.private) + if private ~= obj.private or next(obj.private) then + private = table.clone(obj.private) table.wipe(obj.private) setmetatable(obj.private, {