lianlab / gamekit

Automatically exported from code.google.com/p/gamekit
0 stars 0 forks source link

Class.lua code have problem when lua object inherit parent by the BaseClass function #245

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. create lua codes below
Parent = Class()
function Parent:constructor()
    self.name = "parent"
end
function Parent:f()
    self:a()
    self:b()
end
function Parent:a()
    print( self.name .. "  method a")
end
function Parent:b()
    print( self.name .. "  method b")
end

Child  = BaseClass(Parent) 
function Child:constructor()
    self.name = "child"
end
function Child:a()
print( self.name .. "  method a")
end

testObject = Child()
testObject:f() 
testObject:a()
testObject:b()

What is the expected output? What do you see instead?
the print result is so strange
parent method a
parent method b
parent method a
parent method b

What version of the product are you using? On what operating system?
current repository 

Please provide any additional information below.

attached files have a patch with correct output  and test code
child method a
child method b
child method a
child method b

Original issue reported on code.google.com by kizan...@gmail.com on 6 Jul 2012 at 8:33

Attachments:

GoogleCodeExporter commented 9 years ago
Looks good so far, but your patch breaks the "inheritance" of 
swig-generated-classes.
e.g. see the Runtime/Samples/FSM.blend (line 76).

Could you somehow include this kind of inhertiance too? 

Original comment by thomas.t...@googlemail.com on 9 Jul 2012 at 2:51

GoogleCodeExporter commented 9 years ago
One possible way would be to check to use your kind of inheritance if the type 
to extend is a table and the old version otherwise.
But actually that is not very nice because your version of inheritance for 
lua-based classes seem to work perfect but the one with swig-bases types 
actually doesn't. This is more overwriting plus extending...
Since you seem to know much better about lua-internal stuff, maybe you can find 
a way for both.

Original comment by thomas.t...@googlemail.com on 9 Jul 2012 at 9:10

Attachments:

GoogleCodeExporter commented 9 years ago
hi thomas,
   I had rewrite the lua code, the swig type is ok and also the inheritance ,but  it may be a little ugly. I just add swig type check and then manually overload their function.

Original comment by kizan...@gmail.com on 13 Jul 2012 at 8:53

Attachments:

GoogleCodeExporter commented 9 years ago
Commited your patch. Thx

http://code.google.com/p/gamekit/source/detail?r=1115

Original comment by thomas.t...@googlemail.com on 14 Jul 2012 at 2:24