lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



On Tue, May 16, 2023 at 6:18 AM Mike Schmitz <tmschmitz@gmail.com> wrote:

fd = io.popen("ls /path/to/mods")
File = fd:read()
while File ~= nil do
  Mod = File:match("([^%/%.]+).lua$")
  if Mod ~= nil then require(Mod) end
  File = fd:read()
end

This one's a bit safer, and 'find' has all kinds of options to restrict your search:

local fd <close> = io.popen("find . -maxdepth 1 -type f -name '*.lua' -print0")
local data = "">fd:close()

for f in string.gmatch(data, "[^\0]+") do
    print(f)
end

--