Patch 32 lines of goodness (attempt)

This commit is contained in:
Flameshadowxeroshin
2012-11-23 22:59:45 -06:00
parent d38bba1706
commit d6f3ebd396
+14 -4
View File
@@ -3,19 +3,29 @@
-- Links to original source of code and usage documentation: -- Links to original source of code and usage documentation:
-- http://love2d.org/wiki/32_lines_of_goodness -- http://love2d.org/wiki/32_lines_of_goodness
-- http://love2d.org/forums/viewtopic.php?f=5&t=3344 -- http://love2d.org/forums/viewtopic.php?f=5&t=3344
-- Patches by Robin and FSX (which bring it to 41 lines)
--]] --]]
local mt_class = {} local mt_class = {__index = mt_class, __call = define}
function mt_class:extends(parent) function mt_class:extends(parent)
self.super = parent self.super = parent
setmetatable(mt_class, {__index = parent}) setmetatable(self, {__index = parent, __call=define})
parent.__members__ = parent.__members__ or {} parent.__members__ = parent.__members__ or {}
return self return self
end end
local function define(class, members) local function define(class, members)
class.__members__ = class.__members__ or {} class.__members__ = {}
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 for k, v in pairs(members) do
class.__members__[k] = v class.__members__[k] = v
end end
@@ -35,5 +45,5 @@ end
function class(name) function class(name)
local newclass = {} local newclass = {}
_G[name] = newclass _G[name] = newclass
return setmetatable(newclass, {__index = mt_class, __call = define}) return setmetatable(newclass, mt_class)
end end