From 2264371c6bee821036ac5ffc567bbd11fe2d6b3a Mon Sep 17 00:00:00 2001 From: Matthias Richter Date: Mon, 29 Aug 2011 17:41:05 +0200 Subject: [PATCH] Class commons interface (see https://github.com/bartbes/Class-Commons) --- class.lua | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/class.lua b/class.lua index da94a45..a6e0ec4 100644 --- a/class.lua +++ b/class.lua @@ -32,11 +32,11 @@ local function inherit(class, interface, ...) -- __index and construct are not overwritten as for them class[name] is defined for name, func in pairs(interface) do - if not class[name] and type(func) == "function" then + if not class[name] then class[name] = func end end - for super in pairs(interface.__is_a) do + for super in pairs(interface.__is_a or {}) do class.__is_a[super] = true end @@ -97,6 +97,17 @@ local function new(args) return setmetatable(class, meta) end +-- interface for cross class-system compatibility (see https://github.com/bartbes/Class-Commons). +if class_commons ~= false then + common = common or {} + + function common.class(name, prototype, parent) + local init = prototype.init or (parent or {}).init + return new{name = name, inherits = {prototype, parent}, init} + end +end + + -- the module return setmetatable({new = new, inherit = inherit}, {__call = function(_,...) return new(...) end})