lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Wed, 2011-01-05 at 21:03 -0200, Luciano de Souza wrote: 
> Hi all,
> 
> I was trying to create a graphical interface using IUP with object 
> oriented programming. Something wrong occurs. I prefer to simplify the 
> example to ilustrate what is happining.
> 
> In the original code, the class "parent" defines the window general 
> behavior and the child class is a form inheriting methods and 
> attributes. I prefer to simplify because the quantity of code.
> 
> But the problem is the same: how to access in child class an attribute 
> created in the parent?
> 
> the result of 14th line is "nil", whereas I expected 15 as the answer. I 
> tried self.a in the place of parent.a, but the result is still "nil". I 
> tried to declare in the 5th line "parent.a", but the result is the same.
> 
> 01 require('classlib')
> 02
> 03 class.parent()
> 04 function parent:__init()
> 05 self.a = 15
> 06 end
> 07
> 08 class.child()
> 09 function child:__init()
> 10 self.b = 22
> 11 end
> 12
> 13 function child:display()
> 14 print(parent.a)
> 15 print(self.b)
> 16 end
> 17
> 18 x = child()
> 19 x:display()

Barring any black magic in classlib: where is defined that child is a
subclass of parent?