Skip to content

Add recursive subdirectory inclusion to ix.util.IncludeDir#510

Open
KhallG wants to merge 3 commits intoNebulousCloud:masterfrom
KhallG:master
Open

Add recursive subdirectory inclusion to ix.util.IncludeDir#510
KhallG wants to merge 3 commits intoNebulousCloud:masterfrom
KhallG:master

Conversation

@KhallG
Copy link
Copy Markdown

@KhallG KhallG commented Nov 14, 2025

Add recursive subdirectory inclusion to ix.util.IncludeDir

What changed

Modified ix.util.IncludeDir to 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
end

Key changes

  • Changed file.Find pattern from /*.lua to /* to get both files and directories
  • Added a loop to recursively call IncludeDir on each subdirectory found
  • Preserves the bFromLua parameter through recursive calls

Benefits

  • Better code organization with nested folders
  • Less manual include statements
  • Backward compatible with existing flat directory structures

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.

Refactor the IncludeDir function to improve clarity and structure.
Removed undo functionality for container creation.
@bloodycop6385
Copy link
Copy Markdown
Contributor

This should be an optional argument

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants