mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 06:56:03 +01:00
fix(class): only show warning if constructor is undefined
This commit is contained in:
@@ -50,10 +50,13 @@ local function void() return '' end
|
|||||||
---@param class T
|
---@param class T
|
||||||
---@return T
|
---@return T
|
||||||
function mixins.new(class, ...)
|
function mixins.new(class, ...)
|
||||||
local obj
|
|
||||||
---@cast class +OxClass
|
---@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.
|
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.]])
|
This behaviour is deprecated and will not be supported in the future.]])
|
||||||
:format(class.__name))
|
:format(class.__name))
|
||||||
@@ -63,15 +66,10 @@ This behaviour is deprecated and will not be supported in the future.]])
|
|||||||
if obj.private then
|
if obj.private then
|
||||||
assertType('private', obj.private, 'table')
|
assertType('private', obj.private, 'table')
|
||||||
end
|
end
|
||||||
else
|
|
||||||
obj = {}
|
|
||||||
obj.private = {}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
setmetatable(obj, class)
|
setmetatable(obj, class)
|
||||||
|
|
||||||
local constructor = getConstructor(class)
|
|
||||||
|
|
||||||
if constructor and obj ~= ... then
|
if constructor and obj ~= ... then
|
||||||
local parent = class
|
local parent = class
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user