What are some of the best coding practices to follow when splitting and loading lua code from multiple external lua files, and dealing with lua code from other lualatex packages. This thought comes to mind as I now have a bunch of lua files that I can load and use, but it's not the most cleanly divided code. A couple of questions asked as "Side-note" here are repeated below with more clarity (and additions):
Regarding scope, and possible name clash of "local variables" in external lua files: In the file linebreak.lua of this question, what is the scope of local variables
local n, head, last
? If I load another lua file with "require", and that has similarly named local variables, would that be a problem? Does lua keep local variables local to the functions in the file it is being loaded from? (even if I just loaded them in global namespace)What is the best practice to keep variables and functions in a file from clashing/overriding/interfering with those in another file?
Is it part of lualatex package developers documentation guidelines to document what they are adding to the global namespace? In case a lualatex package does write a name to global namespace, and it clashes with my variable/function name, what's the best place to start debugging?
What is the scoping between two different directlua/latelua blocks? In my observation local variables are local to directlua blocks, and I have ended up using global namespace in past to "pass" values from one directlua block to another. Is there a cleaner way that avoids using global namespace?