-
Notifications
You must be signed in to change notification settings - Fork 0
/
30logstripped.lua
71 lines (59 loc) · 1.34 KB
/
30logstripped.lua
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
local assert = assert
local pairs = pairs
local type = type
local tostring = tostring
local class
local function deep_copy(t, dest, aType)
local t = t or {}
local r = dest or {}
for k,v in pairs(t) do
if aType and type(v)==aType then
r[k] = v
elseif not aType then
if type(v) == 'table' and k ~= "__index" then
r[k] = deep_copy(v)
else
r[k] = v
end
end
end
return r
end
local function instantiate(self,...)
local instance = deep_copy(self)
setmetatable(instance,self)
if self.__init then
if type(self.__init) == 'table' then
deep_copy(self.__init, instance)
else
self.__init(instance, ...)
end
end
return instance
end
local function extends(self,extra_params)
local heir = {}
deep_copy(extra_params, deep_copy(self, heir))
heir.__index = heir
heir.super = self
return setmetatable(heir,self)
end
class = function(attr)
local c = deep_copy(attr)
c.include = function(self,include)
return deep_copy(include, self, 'function')
end
c.new = instantiate
c.extends = extends
c.__index = c
c.is = function(self, kind)
local super
while true do
super = getmetatable(super or self)
if super == kind or super == nil then break end
end
return kind and (super == kind)
end
return c
end
return class