forked from CopilotC-Nvim/CopilotChat.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass.lua
More file actions
38 lines (30 loc) · 617 Bytes
/
class.lua
File metadata and controls
38 lines (30 loc) · 617 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
---@class Class
---@field new fun(...):table
---@field init fun(self, ...)
--- Create class
---@param fn function The class constructor
---@param parent table? The parent class
---@return Class
local function class(fn, parent)
local out = {}
out.__index = out
local mt = {
__call = function(cls, ...)
return cls.new(...)
end,
}
if parent then
mt.__index = parent
end
setmetatable(out, mt)
function out.new(...)
local self = setmetatable({}, out)
fn(self, ...)
return self
end
function out.init(self, ...)
fn(self, ...)
end
return out
end
return class