elua: guarantee multiple inheritance availability on any object
authorDaniel Kolesa <d.kolesa@samsung.com>
Wed, 25 Feb 2015 15:11:52 +0000 (15:11 +0000)
committerDaniel Kolesa <d.kolesa@samsung.com>
Wed, 25 Feb 2015 15:11:52 +0000 (15:11 +0000)
src/bindings/luajit/eina/accessor.lua
src/bindings/luajit/eo.lua
src/scripts/elua/core/util.lua

index 7634590..55afa62 100644 (file)
@@ -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)
index 9067a05..8ebbb38 100644 (file)
@@ -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
index 841ceb0..5333899 100644 (file)
@@ -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)