The import function in the Lua SDK has the restriction: "All files imported from main.lua (and imported from files imported from main.lua, and so on) are compiled into a single pdz file, and import runs the code from the file only once. A second import call from anywhere in the pdz will do nothing."
So if you create a helper package which returns an object or a table of functions, you can only import it in one file—the second place you try to import it, it will be nil. This is a problem for how I like to write small packages which return their contents (instead of making them globals).
Potential workarounds:
- Write my own
cachedImportfunction which stores already-imported packages and returns them. It doesn't work becauseimportrequires a string literal; you can't pass a variable as the path. (But I would support this behavior forimportas an SDK improvement.) - Have my packages expose global functions. I could do this but I don't like it.
- Import all packages in one central place, store them in a global table, and access that table instead of calling
importelsewhere. It's gross, but I'll probably do this.
How do you structure your packages?