mirror of
https://github.com/vrld/hump.git
synced 2024-11-23 12:24:19 +00:00
Update class to match class.commons spec
This commit is contained in:
parent
e2144b525d
commit
31760b00c7
18
class.lua
18
class.lua
@ -62,8 +62,7 @@ local function new(args)
|
|||||||
class.__index = class
|
class.__index = class
|
||||||
class.__tostring = function() return ("<instance of %s>"):format(tostring(class)) end
|
class.__tostring = function() return ("<instance of %s>"):format(tostring(class)) end
|
||||||
class.construct = constructor or __NULL__
|
class.construct = constructor or __NULL__
|
||||||
class.Construct = class.construct
|
class.inherit = inherit
|
||||||
class.inherit, class.Inherit = inherit, inherit
|
|
||||||
class.__is_a = {[class] = true}
|
class.__is_a = {[class] = true}
|
||||||
class.is_a = function(self, other) return not not self.__is_a[other] end
|
class.is_a = function(self, other) return not not self.__is_a[other] end
|
||||||
|
|
||||||
@ -100,18 +99,15 @@ local function new(args)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- interface for cross class-system compatibility (see https://github.com/bartbes/Class-Commons).
|
-- interface for cross class-system compatibility (see https://github.com/bartbes/Class-Commons).
|
||||||
if class_commons ~= false then
|
if class_commons ~= false and not common then
|
||||||
common = common or {}
|
common = {}
|
||||||
function default_init(self, ...)
|
|
||||||
if self.init and self.init ~= default_init then
|
|
||||||
self.init(...)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function common.class(name, prototype, parent)
|
function common.class(name, prototype, parent)
|
||||||
local init = prototype.init or (parent or {}).init or default_init
|
local init = prototype.init or (parent or {}).init
|
||||||
return new{name = name, inherits = {prototype, parent}, init}
|
return new{name = name, inherits = {prototype, parent}, init}
|
||||||
end
|
end
|
||||||
|
function common.instance(class, ...)
|
||||||
|
return class(...)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user