Quantcast WoWInterface - View Single Post - Include files
Thread: Include files
View Single Post
09-21-18, 10:15 AM   #5
doofus
A Flamescale Wyrmkin
Join Date: Feb 2018
Posts: 126
Thanks for the suggestions.

Today I have tried a major restructure, trying to split the one large .lua file into multiple smaller ones, making use of the nameSpace table.

However I am unclear about the order of loading of the .lua files (is it the order in the .toc file?) and the order of initialising static variables.

in file3 I do:

nameSpace["a"]["b"]();

in file2 I do:

nameSpace["a"]["b"] = some_local_function();


and in file1 I do:

nameSpace["a"] = {};

The way I see it, if file1 loads first then nameSpace["a"] becomes a table. If file2 follows, it will have no problem setting nameSpace["a"]["b"] = some function. And finally, file3 can now invoke nameSpace["a"]["b"]();

But it fails in file3 saying that nameSpace["a"]["b"] is nil.

The way around it is to say in file2:

nameSpace["a"] = {};
nameSpace["a"]["b"] = some_local_function();

Then, file3 works as expected.

This begs the question, why was file1's definition not taken into account?
  Reply With Quote