From ce4a2d1620295da7dca776ccce7cc045ed8ef7d0 Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Wed, 18 Jan 2023 22:29:06 -0500 Subject: [PATCH] Swap example order, simpler example first --- .lune/hello_lune.luau | 80 +++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/.lune/hello_lune.luau b/.lune/hello_lune.luau index 425b1ec..7cbf056 100644 --- a/.lune/hello_lune.luau +++ b/.lune/hello_lune.luau @@ -12,46 +12,6 @@ module.hello() --[==[ EXAMPLE #2 - Read files in the current directory - - This prints out directory & file names with some fancy icons -]==] - -print("\nReading current dir 🗂️") -local entries = fs.readDir(".") - --- NOTE: We have to do this outside of the sort function --- to avoid yielding across the metamethod boundary, any --- calls to fs functions may yield for any reason -local dirs = {} -for _, entry in entries do - dirs[entry] = fs.isDir(entry) -end - --- Sort directories first, then alphabetically -table.sort(entries, function(entry0, entry1) - if dirs[entry0] ~= dirs[entry1] then - return dirs[entry0] - end - return entry0 < entry1 -end) - --- Make sure we got some known files that should always exist -assert(table.find(entries, "Cargo.toml") ~= nil, "Missing Cargo.toml") -assert(table.find(entries, "Cargo.lock") ~= nil, "Missing Cargo.lock") - --- Print the pretty stuff -for _, entry in entries do - if fs.isDir(entry) then - print("📁 " .. entry) - else - print("📄 " .. entry) - end -end - ---[==[ - EXAMPLE #3 - Get & set environment variables Checks if environment variables are empty or not, @@ -71,6 +31,46 @@ for _, key in vars do print(string.format("[%s] %s", box, key)) end +--[==[ + EXAMPLE #3 + + Read files in the current directory + + This prints out directory & file names with some fancy icons +]==] + +print("\nReading current dir 🗂️") +local entries = fs.readDir(".") + +-- NOTE: We have to do this outside of the sort function +-- to avoid yielding across the metamethod boundary, any +-- calls to fs functions may yield for any reason +local entryIsDir = {} +for _, entry in entries do + entryIsDir[entry] = fs.isDir(entry) +end + +-- Sort prioritizing directories first, then alphabetically +table.sort(entries, function(entry0, entry1) + if entryIsDir[entry0] ~= entryIsDir[entry1] then + return entryIsDir[entry0] + end + return entry0 < entry1 +end) + +-- Make sure we got some known files that should always exist +assert(table.find(entries, "Cargo.toml") ~= nil, "Missing Cargo.toml") +assert(table.find(entries, "Cargo.lock") ~= nil, "Missing Cargo.lock") + +-- Print the pretty stuff +for _, entry in entries do + if fs.isDir(entry) then + print("📁 " .. entry) + else + print("📄 " .. entry) + end +end + -- NOTE: We skip the last example in GitHub Actions -- since the ping command does not work in azure if process.getEnvVar("GITHUB_ACTIONS") then