-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0class.lua
More file actions
executable file
·34 lines (32 loc) · 959 Bytes
/
0class.lua
File metadata and controls
executable file
·34 lines (32 loc) · 959 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
return function(fields)
local class = {
is = function(self, what)
while self do
if self == what then return true end
self = getmetatable(self)
end
end,
include = function(self, fields)
if not fields then return self end
for k,v in pairs(fields) do
if k ~= "__index" then
self[k] = v
end
end
return self
end,
extends = function(self, fields)
local sub = self.include({}, fields)
sub.super = self
sub.__index = sub
return setmetatable(sub, self)
end,
new = function(self, ...)
local inst = setmetatable({}, self)
local init = self.__init
return init and init(inst, ...) or inst
end
}
class.__index = class
return class:include(fields)
end