I’ve been working on reusable lua modules a lot lately, but I have a problem making them both A) as flexible and easy-to-use as I want, and B) work with Defold’s library dependency system. The problem is, library files are refreshed every time you open the editor, so I can’t require the user to change anything in the module itself, or in any accompanying files. So . . . how do I make a library that can be configured in different ways?
For example, I’m working on a GUI library. I have most of the code in one module, but I’ve separated all the visual stuff (for button press, release, hover, etc.) in a separate “theme” module so it can be more easily customized. You could easily make a new theme module outside the library folder, but you’d still have to change the require
line in the main module, which would be un-done when the editor refreshes the library.
The options I’ve thought about so far are:
- I could pass in data from a script, but that would have to be done before any other scripts try to use the library, which is a pain in the butt.
- I could
require
a file that is outside the library folder. This might be the best option, but it does add more setup work for the user and means the library wouldn’t work “out of the box”. - I could just forget about the Libraries system and make the module however I want. This is easy, but makes setting up the library way more work. Download, unzip, cut, paste, etc., rather than just: copy-paste line to game.project, click “fetch”. And it means you wouldn’t get automatic updates. (which isn’t necessarily a bad thing.)
So I’m looking for other people’s thoughts on this. Both on how to solve it, and how you like to use external libraries, if you care about the library dependency thing or not, etc. Thanks!