mirror of
https://github.com/lune-org/lune.git
synced 2025-01-05 19:09:10 +00:00
Swap example order, simpler example first
This commit is contained in:
parent
49b01d37b1
commit
ce4a2d1620
1 changed files with 40 additions and 40 deletions
|
@ -12,46 +12,6 @@ module.hello()
|
||||||
--[==[
|
--[==[
|
||||||
EXAMPLE #2
|
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
|
Get & set environment variables
|
||||||
|
|
||||||
Checks if environment variables are empty or not,
|
Checks if environment variables are empty or not,
|
||||||
|
@ -71,6 +31,46 @@ for _, key in vars do
|
||||||
print(string.format("[%s] %s", box, key))
|
print(string.format("[%s] %s", box, key))
|
||||||
end
|
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
|
-- NOTE: We skip the last example in GitHub Actions
|
||||||
-- since the ping command does not work in azure
|
-- since the ping command does not work in azure
|
||||||
if process.getEnvVar("GITHUB_ACTIONS") then
|
if process.getEnvVar("GITHUB_ACTIONS") then
|
||||||
|
|
Loading…
Reference in a new issue