Add recursive subdirectory inclusion to ix.util.IncludeDir#510
Open
KhallG wants to merge 3 commits intoNebulousCloud:masterfrom
Open
Add recursive subdirectory inclusion to ix.util.IncludeDir#510KhallG wants to merge 3 commits intoNebulousCloud:masterfrom
KhallG wants to merge 3 commits intoNebulousCloud:masterfrom
Conversation
Refactor the IncludeDir function to improve clarity and structure.
Removed undo functionality for container creation.
Contributor
|
This should be an optional argument |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add recursive subdirectory inclusion to
ix.util.IncludeDirWhat changed
Modified
ix.util.IncludeDirto recursively include Lua files from subdirectories instead of just the top-level directory.Why
The current implementation only processes files in the immediate directory. If you want to organize code into subfolders, you have to manually include each one. This change makes the function automatically traverse subdirectories, which is more intuitive and reduces boilerplate.
Implementation
function ix.util.IncludeDir(directory, bFromLua) local baseDir = "helix" if (Schema and Schema.folder and Schema.loading) then baseDir = Schema.folder.."/schema/" else baseDir = baseDir.."/gamemode/" end - -- Find all of the files within the directory. - for _, v in ipairs(file.Find((bFromLua and "" or baseDir)..directory.."/*.lua", "LUA")) do - -- Include the file from the prefix. + -- Find all files and subdirectories + local files, dirs = file.Find((bFromLua and "" or baseDir)..directory.."/*", "LUA") + + -- Include all Lua files in current directory + for _, v in ipairs(files) do ix.util.Include(directory.."/"..v) end + + -- Recursively process subdirectories + for _, d in ipairs(dirs) do + ix.util.IncludeDir(directory.."/"..d, bFromLua) + end endKey changes
file.Findpattern from/*.luato/*to get both files and directoriesIncludeDiron each subdirectory foundbFromLuaparameter through recursive callsBenefits
Notes
This is fully backward compatible. Existing code that uses single-level directories will continue to work unchanged. The function simply handles nested structures automatically now.