It looks like you're new here. If you want to get involved, click one of these buttons!
I have this file
----------------
-- Class: Animal
----------------
Animal = class()
function Animal:init( word )
self.talk = word
end
function Animal:speak()
print( self.talk )
end
----------------
-- Class: Dog
----------------
Dog = class(Animal)
function Dog:init()
Animal.init( self, "Woof" )
end
----------------
-- Main
----------------
function setup()
d = Dog()
d:speak()
c = Animal("Meow")
c:speak()
end
This works no problem, but if you separate the classes across two files, it will not inherit the Animal class. How do I separate the class in two files and still be able to inherit?
Comments
1/ from your project A editor, tap the + sign on top right.
2/ in 'dependencies', check the other project B with you classes.
tadaaaaa! project A knows your classes in B
I figured it out, file execution order matters. The classes are excuted from left to right in the tab, I had my super class execute after the subclass inherited, so my subclass was inheriting when the superclass was still null.
@Jmv28 thanks! I didn't make my self clear that I was talking about the same project
You know I didn't see anywhere in the doc about execution order, but it turns out it's a thing. Is it me or is it actually not documented?
Probably not documented. There are a few thing that aren't documented, you'll find those as you write more code.
It's a quirky thing about Codea/Lua. You can also have multiple copies of the same functions, and Codea will use the right hand one.
@Simeon had to pick some order for compiling the tabs. The choices available were either alphabetical, time created, or how they're ordered in the project.
Tab ordering is documented here: https://bitbucket.org/TwoLivesLeft/core/wiki/CodeaMain
Although it could perhaps add that subclasses need to be below/ to the right of their parents