forked from etternagame/etterna
-
Notifications
You must be signed in to change notification settings - Fork 0
/
32log.lua
48 lines (45 loc) · 1.19 KB
/
32log.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
--[[
-- 32 lines of goodness.
-- Links to original source of code and usage documentation:
-- http://love2d.org/wiki/32_lines_of_goodness
-- http://love2d.org/forums/viewtopic.php?f=5&t=3344
-- Patches by Robin and FSX (which bring it to 41 lines)
--]]
local mt_class = {__index = mt_class, __call = define}
function mt_class:extends(parent)
self.super = parent
setmetatable(self, {__index = parent, __call = define})
parent.__members__ = parent.__members__ or {}
return self
end
local function define(class, members)
class.__members__ = class.__members__ or {}
local function copyMembersDown(origin, cls)
if cls.super then
for k, v in pairs(cls.super.__members__) do
origin[k] = v
end
return copyMembersDown(origin, cls.super)
end
end
copyMembersDown(class.__members__, class)
for k, v in pairs(members) do
class.__members__[k] = v
end
function class:new(...)
local newvalue = {}
for k, v in pairs(class.__members__) do
newvalue[k] = v
end
setmetatable(newvalue, {__index = class})
if newvalue.__init then
newvalue:__init(...)
end
return newvalue
end
end
function class(name)
local newclass = {}
_G[name] = newclass
return setmetatable(newclass, mt_class)
end