Skip to content

Commit

Permalink
feat(class): allow private to be redefined
Browse files Browse the repository at this point in the history
Allows self.private to defined as a new table, allowing it to
remain empty without being removed after instantiation.

Resolves #696.
  • Loading branch information
thelindat committed Jan 25, 2025
1 parent 3751945 commit 8af94a7
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions imports/class/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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, {
Expand Down

0 comments on commit 8af94a7

Please sign in to comment.