Thread: Multiple file
View Single Post
07/18/16, 10:16 PM   #6
Randactyl
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 251
It's just safety and is not totally necessary.

Let's say you have two files, main.lua and settings.lua, and that main.lua is listed first in the manifest.

At the top of main.lua you could write

Code:
myNamespace = {}
because it is your namespace and this is the first time you're bringing it into the world.

Afterward, in settings.lua, you could either assume myNamespace exists since it should have been created in the first file, or you can chose to set it to a new table if it is still nil for some reason (the previous example).

However, if you were to write

Code:
myNamespace = {}
in settings.lua, you would be explicitly discarding anything that was done to the version of myNamespace that was set up in main.lua.

Now, a possible benefit of having the redundancy of

Code:
myNamespace = myNamespace or {}
is if somewhere down the line you decide you need to shuffle around the order in which files are loaded. This line could save you an error there if you forget to also shuffle where your namespace is initially declared.
  Reply With Quote