Hello,
I need your help again.
Currently, my project has more 3000 lines in its largest/main file. I have read that in Lua only global functions can be shared from separate files.
Since I am using Scenemanager, most of my function declarations are local (if I understand well scoping in Lua) like:
function level1:myfunction()
So my question is: how do you split your code? Do you?
Comments
I think i use global functions.
You can have a look at some sample projects, for example rrraptor gh or my gh (see signature).
Or this http://forum.giderosmobile.com/discussion/comment/63462/#Comment_63462
"What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
“The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
function level1:onEnterFrame(e)
when "level1" has been created in level1.lua.
That is just an example. I don't intend to extract the main loop from its original file. However, I have a bunch of functions that look like that.
I have to consider this.
- Organize your code in classes/namespaces, with all methods of the same class in the same file.
- Avoid 'require' and use code dependencies and --!NEEDS:file.lua to deal with loading order. This is Gideros specific though, if you plan to reuse your code in another engine, then go for 'require'
- If some code files get too big and unreadable, try to find a way to seperate it in two or more sub-functionnalities and give them their own namespace/table/class
- Use camel case for function names and class names
- Use upper case for other global things (instances, constants)
- Add comments around pieces of code that are not easy to read or understand at first sight
Likes: oleg, jdbc
https://play.google.com/store/apps/developer?id=razorback456
мій блог по гідерос https://simartinfo.blogspot.com
Слава Україні!
Also, there is --!NOEXEC tag that does not load a file, so you have to do it by yourself using require function.
Likes: oleg
Likes: MoKaLux
under Loading Order of Lua Files
Likes: SinisterSoft
Take a look to my game Dots, the source code is available on github:
https://github.com/jdbcdev/Dots
Likes: MoKaLux