I’m reading through the manual to get to know both Defold and Lua better while developing the game, I came across this section (http://www.defold.com/manuals/modules/) and noticed that in the section where you introduce name spaces, that you name the namespace to “M” but then use “flying” when accessing the actual variable in it.
I haven’t got to the point to make use of namespaces myself, but I am guessing it’s wrong?
Well ok, I see you use M inside of the module, but then name it “flying” outside of it. I guess it’s a preferred practice that you have in the company?
It’s a preferred practice for Lua: http://www.lua.org/pil/15.1.html
It allows you to not pollute global namespace and avoid name clashes. The approach is very similar to Javascript. You create a module but end user decides the name that will be used for this module. I find this approach really great.
Alright, so I did some tests. The functions I place in “M”, can either reference the global name I set out for the module when requiring the file,or the local name “M”. I also see in the preferred practice page that it uses “P” (it’s alternative for “M”) when calling functions within it’s own module/package, but Defold manual refers to the global name (which by the time the code is being written may not exist, thus be more confusing than enlightening).
All in all I’m asking, would it not be easier to present the code if within a module, you referenced “M” instead of “flying”, which isn’t created yet, until you’ve done the “require”-statement, which in this case comes first in next code box? It would make it easier for a new user to read the code from top to bottom and be able to understand each line, without having to read the end to understand the beginning.