mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-16 22:46:03 +01:00
refactor(class): remove support for class.init
This commit is contained in:
@@ -55,25 +55,12 @@ local function void() return '' end
|
|||||||
---@return T
|
---@return T
|
||||||
function mixins.new(class, ...)
|
function mixins.new(class, ...)
|
||||||
local constructor = getConstructor(class)
|
local constructor = getConstructor(class)
|
||||||
local obj = {
|
|
||||||
|
local obj = setmetatable({
|
||||||
private = {}
|
private = {}
|
||||||
}
|
}, class)
|
||||||
|
|
||||||
if not constructor and table.type(...) == 'hash' then
|
if constructor 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))
|
|
||||||
|
|
||||||
obj = ...
|
|
||||||
|
|
||||||
if obj.private then
|
|
||||||
assertType('private', obj.private, 'table')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
setmetatable(obj, class)
|
|
||||||
|
|
||||||
if constructor and obj ~= ... then
|
|
||||||
local parent = class
|
local parent = class
|
||||||
|
|
||||||
function obj:super(...)
|
function obj:super(...)
|
||||||
@@ -84,13 +71,6 @@ This behaviour is deprecated and will not be supported in the future.]])
|
|||||||
end
|
end
|
||||||
|
|
||||||
constructor(obj, ...)
|
constructor(obj, ...)
|
||||||
---@diagnostic disable-next-line: undefined-field
|
|
||||||
elseif class.init then
|
|
||||||
lib.print.warn(([[Calling %s:init() is deprecated and will not be supported in the future.
|
|
||||||
Use %s:constructor(...args) and assign properties in the constructor.]])
|
|
||||||
:format(class.__name, class.__name))
|
|
||||||
|
|
||||||
obj:init()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
obj.super = nil
|
obj.super = nil
|
||||||
@@ -113,7 +93,7 @@ Use %s:constructor(...args) and assign properties in the constructor.]])
|
|||||||
local di = getinfo(2, 'n')
|
local di = getinfo(2, 'n')
|
||||||
|
|
||||||
if di.namewhat ~= 'method' then
|
if di.namewhat ~= 'method' then
|
||||||
error(("cannot set values on private field '%s'"):format(index), 2)
|
error(("cannot set value of private field '%s'"):format(index), 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
private[index] = value
|
private[index] = value
|
||||||
|
|||||||
Reference in New Issue
Block a user