From 212571c40618f0b3a1c336d73548fd021e6cd278 Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Wed, 25 Feb 2015 15:11:52 +0000 Subject: [PATCH] elua: guarantee multiple inheritance availability on any object --- src/bindings/luajit/eina/accessor.lua | 2 +- src/bindings/luajit/eo.lua | 2 +- src/scripts/elua/core/util.lua | 19 +++++-------------- 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/src/bindings/luajit/eina/accessor.lua b/src/bindings/luajit/eina/accessor.lua index 7634590d0e..55afa62427 100644 --- a/src/bindings/luajit/eina/accessor.lua +++ b/src/bindings/luajit/eina/accessor.lua @@ -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) diff --git a/src/bindings/luajit/eo.lua b/src/bindings/luajit/eo.lua index 9067a057b0..8ebbb383e4 100644 --- a/src/bindings/luajit/eo.lua +++ b/src/bindings/luajit/eo.lua @@ -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 diff --git a/src/scripts/elua/core/util.lua b/src/scripts/elua/core/util.lua index 841ceb08ca..533389904f 100644 --- a/src/scripts/elua/core/util.lua +++ b/src/scripts/elua/core/util.lua @@ -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)