lualine.nvim/lua/lualine/utils/class.lua

44 lines
787 B
Lua
Raw Normal View History

-- 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
function Object:init(...) end
-- luacheck: pop
2021-10-12 14:04:47 +00:00
---Extened base class to create a child class
function Object:extend()
local cls = {}
for k, v in pairs(self) do
if k:find '__' == 1 then
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
function Object:new(...)
local obj = setmetatable({}, self)
obj:init(...)
return obj
end
2021-10-12 14:04:47 +00:00
---Creates a new object
function Object:__call(...)
return self:new(...)
end
return Object