-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.lua
47 lines (42 loc) · 826 Bytes
/
utils.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
local function chain(loveFunc, func, after)
return function (...)
if loveFunc and after then
loveFunc(...)
end
func(...)
if loveFunc and not after then
loveFunc(...)
end
end
end
local function loveChain(instance, funcNames)
for i=1, #funcNames do
local key = funcNames[i]
love[key] = chain(love[key], function (...)
instance[key](instance, ...)
end)
end
end
local function class(base)
local Klass = {}
Klass.__index = Klass
setmetatable(Klass, {
__call = function (s, ...)
local o = {}
if base then
setmetatable(s, base)
o = base(...)
end
o = setmetatable(o, s)
if o.init then
o:init(...)
end
return o
end
})
return Klass
end
return {
class = class,
loveChain = loveChain,
}