Object = require 'classic'
ClassA = Object:extend()
function ClassA:new(x)
self.x = x
print(self.x)
end
ClassB = ClassA:extend()
function ClassB:new(x)
ClassB.super:new(x)
end
ClassC = ClassA:extend()
function ClassC:new(x)
ClassC.super:new(x)
end
local a = ClassA('a')
local b = ClassB('b')
local c = ClassC('c')
print(b.x)
I thought result should be as:
a
b
c
b
but I got:
a
b
c
c
Did I make something wrong or the library has some flaw to fix?
This is, because ClassB etc. are class instances and when you use super:new and not use the explicit self of the current scope, you call those upper constructors with the actual class instance rather than your object instance.
This is, because ClassB etc. are class instances and when you use super:new and not use the explicit self of the current scope, you call those upper constructors with the actual class instance rather than your object instance.
Thank you Nelvin, I got it, seems I shall care more about ':' in lua:D