EMILUA(3em)

πŸ“¦ version 0.12.1, in nixos 26.05, nixpkgs unstable

🌸 NAME 🌸

Emilua β€” Lua execution engine. This is the EMILUA(3em) page, bestie, and we’re gonna get you comfy with it πŸ’–


✨ SYNOPSIS ✨

Copy this exactly, no cap:

           local fs = require "filesystem"
           fs.recursive_directory_iterator(p: fs.path[, opts: table]) -> function, handle

πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so this returns an iterator function, plus a handle you can use to control the iteration.

Every time you call that iterator, it gives you back a filesystem.directory_entry object for an element of the directory p β€” and yes, recursively over the entries of all of its subdirectories too β€” plus the current recursion depth, which is an integer. Slay.

πŸŽ€ opts πŸŽ€

  • skip_permission_denied: boolean = false β€” whether to skip directories that would otherwise result in EPERM.
  • follow_directory_symlink: boolean = false β€” whether to follow directory symlinks.

🧚 WRAPPING THE ITERATOR TO SKIP OVER CVS FILES. 🧚

Some programs, like rsync, have command line options such as --cvs-exclude that skip over unwanted files for the directory traversal. Those patterns are easy to abstract on top of recursive_directory_iterator. Here’s the implementation for a function that does exactly that, bestie:

           function cvs_exclude(iter, ctrl)
               local function next()
                   local entry, depth = iter()
                   if entry == nil then
                       return
                   end

                   local p = entry.path.filename
                   if p == ".git" or p == ".svn" or p == ".hg" then
                       ctrl:disable_recursion_pending()
                   end
                   return entry, depth
               end
               return next, ctrl
           end
πŸŽ€ Tip: The same trick can be used to create functions to perform shell globbing. Iconic.

🫢 handle FUNCTIONS 🫢

  • pop(self) β€” moves the iterator one level up in the directory hierarchy.
  • disable_recursion_pending(self) β€” disables recursion until the next increment.

πŸ’… handle PROPERTIES πŸ’…

  • recursion_pending: boolean β€” whether the recursion is disabled for the current directory.

πŸ”₯ EXAMPLE πŸ”₯

           local fs = require "filesystem"

           for entry, depth in fs.recursive_directory_iterator(fs.path.new(".")) do
               print(string.rep("\t", depth) .. entry.path.filename)
           end

πŸ’– That’s the whole vibe, bestie πŸ’– β€” brought to you by Emilua 0.12.1-nixpkgs1, dated 1980-01-01, living its best life as EMILUA(3em). Mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from