Allow developers to use complex settings files
Attempting to load a more complex config.lua will raise a warning and attempting to do the same with build.settings seems to result in the file not being loaded entirely.
This "complex file" may be attributed to loading a single configuration file via require() in either file, so allow the developers to explicitly set their settings as a complexFile to allow them to be validated as normal.
Currently in the PR:
- fixed one minor typo in 91615ba
- added support for including text tag "isComplexFile" anywhere in config.lua, which will allow Solar2D to skip the initial file validation and suppress outputting a warning regarding complex files. By the time the file is actually loaded and not just validated, then requiring external modules (and other functions) will work correctly. NB! This only works with config.lua and not with build.settings.
Example usage in config.lua:
-- isComplexFile: suppresses initial file validation warnings.
local gameConfig = require("configs.gameConfig")
application =
{
content =
{
width = gameConfig.contentWidth,
height = gameConfig.contentHeight,
scale = "letterbox",
fps = gameConfig.fps,
},
license =
{
google =
{
key = gameConfig.licenseGoogle,
},
},
}
Since we're using string.find() to find the "isComplexFile" tag, it can be anywhere in the file as a simple comment.
In case someone finds this later, you can suppress the warnings in config.lua by just checking for any Solar2D specific Lua API in the global table.
As config.lua is loaded twice, first to conduct basic static file analysis, and a second time to read the file for the application's configuration, certain libraries like _G.native will not exist during the static file analysis phase. In other words, you can suppress the warnings by first checking if _G.native then and running your code afterwards.