From 356f46d7efd29acff2e54b2ae05ec85750a4e8c1 Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Wed, 13 Mar 2024 00:01:17 +1100 Subject: [PATCH] fix(class): only show warning if constructor is undefined --- imports/class/shared.lua | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/imports/class/shared.lua b/imports/class/shared.lua index 5b8b454..fa3f452 100644 --- a/imports/class/shared.lua +++ b/imports/class/shared.lua @@ -50,10 +50,13 @@ local function void() return '' end ---@param class T ---@return T function mixins.new(class, ...) - local obj ---@cast class +OxClass + local constructor = getConstructor(class) + local obj = { + private = {} + } - if table.type(...) == 'hash' then + if not constructor and table.type(...) == 'hash' then lib.print.warn(([[Creating instance of %s with a table and no constructor. This behaviour is deprecated and will not be supported in the future.]]) :format(class.__name)) @@ -63,15 +66,10 @@ This behaviour is deprecated and will not be supported in the future.]]) if obj.private then assertType('private', obj.private, 'table') end - else - obj = {} - obj.private = {} end setmetatable(obj, class) - local constructor = getConstructor(class) - if constructor and obj ~= ... then local parent = class