forked from enlightenment/efl
elua: guarantee multiple inheritance availability on any object
This commit is contained in:
parent
4ecedc5198
commit
212571c406
|
@ -102,7 +102,7 @@ M.Accessor = util.Readonly_Object:clone {
|
|||
clone = function(self)
|
||||
self = dgetmt(self)
|
||||
if not self.__accessor then return nil end
|
||||
return self.__proto(self.__accessor:clone())
|
||||
return self.__protos[1](self.__accessor:clone())
|
||||
end,
|
||||
|
||||
data_get = function(self, pos)
|
||||
|
|
|
@ -203,7 +203,7 @@ local mixin_tbl = function(cl, mixin, field)
|
|||
local clt = rawget(cl, field)
|
||||
if not clt then
|
||||
-- will always succeed, even if it means deep lookups
|
||||
clt = cl.__proto[field]:clone()
|
||||
clt = cl.__protos[1][field]:clone()
|
||||
rawset(cl, field, clt)
|
||||
end
|
||||
for k, v in pairs(mxt) do clt[k] = v end
|
||||
|
|
|
@ -15,6 +15,7 @@ local getmetatable, setmetatable = getmetatable, setmetatable
|
|||
|
||||
-- multiple inheritance index with depth-first search
|
||||
local proto_lookup = function(protos, name)
|
||||
if not protos then return nil end
|
||||
for i = 1, #protos do
|
||||
local proto = protos[i]
|
||||
local v = proto[name]
|
||||
|
@ -40,7 +41,8 @@ M.Object = {
|
|||
|
||||
clone = function(self, o)
|
||||
o = o or {}
|
||||
o.__index, o.__proto, o.__call = self, self, self.__call
|
||||
o.__index, o.__protos, o.__mixins, o.__call =
|
||||
multi_index, { self }, {}, self.__call
|
||||
if not o.__tostring then
|
||||
o.__tostring = self.__tostring
|
||||
end
|
||||
|
@ -61,23 +63,12 @@ M.Object = {
|
|||
|
||||
add_parent = function(self, parent)
|
||||
local protos = self.__protos
|
||||
if protos then
|
||||
-- we have multiple inheritance set up
|
||||
protos[#protos + 1] = parent
|
||||
else
|
||||
self.__protos = { self.__proto, parent }
|
||||
self.__proto = nil
|
||||
self.__index = multi_index
|
||||
end
|
||||
protos[#protos + 1] = parent
|
||||
end,
|
||||
|
||||
add_mixin = function(self, mixin)
|
||||
local mixins = self.__mixins
|
||||
if mixins then
|
||||
mixins[#mixins + 1] = mixin
|
||||
else
|
||||
self.__mixins = { mixin }
|
||||
end
|
||||
mixins[#mixins + 1] = mixin
|
||||
end,
|
||||
|
||||
__tostring = function(self)
|
||||
|
|
Loading…
Reference in New Issue