mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-18 15:36:02 +01:00
refactor(class): use mixins for default class methods
This commit is contained in:
@@ -21,8 +21,10 @@ local function assertType(id, var, expected)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local mixins = {}
|
||||||
|
|
||||||
---Creates a new instance of the given class.
|
---Creates a new instance of the given class.
|
||||||
local function createObj(class, obj)
|
function mixins.new(class, obj)
|
||||||
if obj.private then
|
if obj.private then
|
||||||
assertType('private', obj.private, 'table')
|
assertType('private', obj.private, 'table')
|
||||||
setmetatable(obj.private, private_mt)
|
setmetatable(obj.private, private_mt)
|
||||||
@@ -42,11 +44,9 @@ end
|
|||||||
function lib.class(name, super)
|
function lib.class(name, super)
|
||||||
assertType(1, name, 'string')
|
assertType(1, name, 'string')
|
||||||
|
|
||||||
local class = {
|
local class = table.clone(mixins)
|
||||||
__name = name,
|
|
||||||
new = createObj,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
class.__name = name
|
||||||
class.__index = class
|
class.__index = class
|
||||||
|
|
||||||
return super and setmetatable(class, super) or class
|
return super and setmetatable(class, super) or class
|
||||||
|
|||||||
Reference in New Issue
Block a user