Debian Codegraph @

lua/lualine/utils/class.lua

raw
1 -- Adapted from https://github.com/rxi/classic/blob/master/classic.lua
2 local Object = {}
3
4 Object.__index = Object
5
6 -- luacheck: push no unused args
7 ---Initializer
8 function Object:init(...) end
9 -- luacheck: pop
10
11 ---Extend base class to create a child class
12 function Object:extend()
13 local cls = {}
14 for k, v in pairs(self) do
15 if k:find('__') == 1 then
16 cls[k] = v
17 end
18 end
19 cls.__index = cls
20 cls.super = self
21 setmetatable(cls, self)
22 return cls
23 end
24
25 -- luacheck: push no unused args
26 function Object:__tostring()
27 return 'Object'
28 end
29 -- luacheck: pop
30
31 ---Creates a new object
32 function Object:new(...)
33 local obj = setmetatable({}, self)
34 obj:init(...)
35 return obj
36 end
37
38 ---Creates a new object
39 function Object:__call(...)
40 return self:new(...)
41 end
42
43 return Object