Skip to content

Commit

Permalink
fix(class): only show warning if constructor is undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
thelindat committed Mar 12, 2024
1 parent d105ebe commit 356f46d
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions imports/class/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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

Expand Down

0 comments on commit 356f46d

Please sign in to comment.