elua: correct eo inheritance behavior

Now we try to treat first inherit as a parent and everything else as a mixin.
If the first inherit is not a class (interface or mixin), every inherit is
treated as a mixin.

@fix
This commit is contained in:
Daniel Kolesa 2015-02-05 11:10:29 +00:00
parent cd0cca6f80
commit 8abe1a06f8
1 changed files with 14 additions and 11 deletions

View File

@ -638,22 +638,25 @@ local gen_mixin = function(klass)
end
local gen_class = function(klass)
local inherits = klass:inherits_get()
local inherits = klass:inherits_get():to_array()
local parent
local mixins = {}
local mixins = {}
local ct = eolian.class_type
for v in inherits do
local tp = eolian.class_get_by_name(v):type_get()
local n = 1
if inherits[n] then
local tp = eolian.class_get_by_name(inherits[n]):type_get()
if tp == ct.REGULAR or tp == ct.ABSTRACT then
if parent then
error(klass:full_name_get() .. ": more than 1 parent!")
end
parent = v
elseif tp == ct.MIXIN or tp == ct.INTERFACE then
mixins[#mixins + 1] = v
else
parent = inherits[n]
n = n + 1
end
end
for i = n, #inherits do
local v = inherits[i]
local tp = eolian.class_get_by_name(v):type_get()
if tp == ct.UNKNOWN then
error(klass:full_name_get() .. ": unknown inherit " .. v)
end
mixins[#mixins + 1] = v
end
return Class(klass, parent, mixins, gen_contents(klass))
end