2021-09-25 17:15:42 +00:00
|
|
|
-- Adapted from https://github.com/rxi/classic/blob/master/classic.lua
|
|
|
|
local Object = {}
|
|
|
|
|
|
|
|
Object.__index = Object
|
|
|
|
|
|
|
|
-- luacheck: push no unused args
|
2021-10-12 14:04:47 +00:00
|
|
|
---Initializer
|
2021-09-25 17:15:42 +00:00
|
|
|
function Object:init(...) end
|
|
|
|
-- luacheck: pop
|
|
|
|
|
2021-10-12 14:04:47 +00:00
|
|
|
---Extened base class to create a child class
|
2021-09-25 17:15:42 +00:00
|
|
|
function Object:extend()
|
|
|
|
local cls = {}
|
|
|
|
for k, v in pairs(self) do
|
2022-01-02 11:38:39 +00:00
|
|
|
if k:find('__') == 1 then
|
2021-09-25 17:15:42 +00:00
|
|
|
cls[k] = v
|
|
|
|
end
|
|
|
|
end
|
|
|
|
cls.__index = cls
|
|
|
|
cls.super = self
|
|
|
|
setmetatable(cls, self)
|
|
|
|
return cls
|
|
|
|
end
|
|
|
|
|
|
|
|
-- luacheck: push no unused args
|
|
|
|
function Object:__tostring()
|
|
|
|
return 'Object'
|
|
|
|
end
|
|
|
|
-- luacheck: pop
|
|
|
|
|
2021-10-12 14:04:47 +00:00
|
|
|
---Creates a new object
|
2021-09-25 17:15:42 +00:00
|
|
|
function Object:new(...)
|
|
|
|
local obj = setmetatable({}, self)
|
|
|
|
obj:init(...)
|
|
|
|
return obj
|
|
|
|
end
|
|
|
|
|
2021-10-12 14:04:47 +00:00
|
|
|
---Creates a new object
|
2021-09-25 17:15:42 +00:00
|
|
|
function Object:__call(...)
|
|
|
|
return self:new(...)
|
|
|
|
end
|
|
|
|
|
|
|
|
return Object
|