summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid McMackins II <contact@mcmackins.org>2015-07-05 22:21:57 -0500
committerDavid McMackins II <contact@mcmackins.org>2015-07-05 22:21:57 -0500
commit096c55e302215f68190abbcd6d878e2e1e9de9bf (patch)
treee1d492e39f8c7020247d5e1b9a60e8dde19840a4
parentc87d83c8111781d979519c03efd5e08d397e59d4 (diff)
Allowing override of constructor and changed name to be more obviously private to the class
-rw-r--r--class.lua18
1 files changed, 9 insertions, 9 deletions
diff --git a/class.lua b/class.lua
index 8205b0a..730b304 100644
--- a/class.lua
+++ b/class.lua
@@ -16,11 +16,11 @@ SOFTWARE.
--]]
-function class(base, init)
+function class(base, __init)
local c = {}
- if not init and type(base) == 'function' then
- init = base
+ if not __init and type(base) == 'function' then
+ __init = base
base = nil
elseif type(base) == 'table' then
for i,v in pairs(base) do
@@ -35,20 +35,20 @@ function class(base, init)
local mt = {}
mt.__call = function(class_tbl, ...)
local obj = {}
- setmetatable(obj,c)
+ setmetatable(obj, c)
- if init then
- init(obj,...)
+ if class_tbl.__init then
+ class_tbl.__init(obj, ...)
else
- if base and base.init then
- base.init(obj, ...)
+ if base and base.__init then
+ base.__init(obj, ...)
end
end
return obj
end
- c.init = init
+ c.__init = __init
c.is_a = function(self, klass)
local m = getmetatable(self)
while m do