mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-18 15:36:02 +01:00
feat(class): add temporary super method during class init
This commit is contained in:
@@ -16,8 +16,8 @@ local function assertType(id, var, expected)
|
|||||||
|
|
||||||
if received ~= expected then
|
if received ~= expected then
|
||||||
error(
|
error(
|
||||||
("expected %s %s to have type '%s' (received %s)"):format(type(id) == 'string' and 'field' or 'argument', id,
|
("expected %s %s to have type '%s' (received %s)"):format(type(id) == 'string' and 'field' or 'argument', id,
|
||||||
expected, received), 3)
|
expected, received), 3)
|
||||||
end
|
end
|
||||||
|
|
||||||
return true
|
return true
|
||||||
@@ -34,7 +34,19 @@ function mixins.new(class, obj)
|
|||||||
|
|
||||||
setmetatable(obj, class)
|
setmetatable(obj, class)
|
||||||
|
|
||||||
if class.init then obj:init() end
|
if class.init then
|
||||||
|
local parent = class
|
||||||
|
|
||||||
|
function obj:super(...)
|
||||||
|
parent = getmetatable(parent)
|
||||||
|
local superInit = parent and parent.init
|
||||||
|
|
||||||
|
if superInit then return superInit(self, ...) end
|
||||||
|
end
|
||||||
|
|
||||||
|
obj:init()
|
||||||
|
obj.super = nil
|
||||||
|
end
|
||||||
|
|
||||||
return obj
|
return obj
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user