summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid McMackins II <contact@mcmackins.org>2015-07-05 22:07:58 -0500
committerDavid McMackins II <contact@mcmackins.org>2015-07-05 22:07:58 -0500
commitc87d83c8111781d979519c03efd5e08d397e59d4 (patch)
tree5f2c1e9bbfe87d9d701f1c1b3730e0a32fbb8d0e
parent62e714e6eff527491111a1f5a1f95d530f595dfe (diff)
Clean up a bit
-rw-r--r--class.lua22
1 files changed, 15 insertions, 7 deletions
diff --git a/class.lua b/class.lua
index 67259b6..8205b0a 100644
--- a/class.lua
+++ b/class.lua
@@ -18,6 +18,7 @@ SOFTWARE.
function class(base, init)
local c = {}
+
if not init and type(base) == 'function' then
init = base
base = nil
@@ -25,23 +26,28 @@ function class(base, init)
for i,v in pairs(base) do
c[i] = v
end
+
c._base = base
end
+
c.__index = c
local mt = {}
mt.__call = function(class_tbl, ...)
local obj = {}
setmetatable(obj,c)
- if init then
- init(obj,...)
- else
- if base and base.init then
- base.init(obj, ...)
+
+ if init then
+ init(obj,...)
+ else
+ if base and base.init then
+ base.init(obj, ...)
+ end
end
+
+ return obj
end
- return obj
- end
+
c.init = init
c.is_a = function(self, klass)
local m = getmetatable(self)
@@ -49,8 +55,10 @@ function class(base, init)
if m == klass then return true end
m = m._base
end
+
return false
end
+
setmetatable(c, mt)
return c
end