Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

weirdness calling superclass method #25

Open
colinator opened this Issue Feb 26, 2011 · 0 comments

Comments

Projects
None yet
1 participant

According to the docs, I thought the way to call a superclass method
was "self.super:methodname(self)", no? It doesn't quite work:

With this code:

waxClass{"ParentClass", NSObject}

function init(self, options)
self = self.super:init()
self.k = options.k
return self
end

function doit(self)
print("ParentClass:doit")
print(self)
print(self.k)
end

waxClass{"ChildClass", ParentClass}

function init(self, options)
self = self.super:init(options)
self.v = options.v
return self
end

function doit(self)
print("ChildClass:doit")
print(self)
print(self.k)
print(self.v)
self.super:doit(self)
end

local v = ChildClass:init({ k = "blah", v = "yada"})
v:doit()

I get (notice that the self output changes in the child class, and
it's self.k value is now nil):

ChildClass:doit
(0xcb14674 => 0xcb14a90) <ChildClass: 0xcb14a90>
blah
yada
ParentClass:doit
(0xcb14504 => 0xcb14a90) <ChildClass: 0xcb14a90>
nil

Note that a successful workaround is:
self.super.doit(self)

I dunno if that's acceptable going forward or not...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment