mirror of
https://github.com/vrld/hump.git
synced 2024-10-15 09:04:18 +00:00
Class commons interface (see https://github.com/bartbes/Class-Commons)
This commit is contained in:
parent
6089ad4494
commit
2264371c6b
15
class.lua
15
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})
|
||||
|
Loading…
Reference in New Issue
Block a user