Init
This commit is contained in:
commit
c0b5de5a4f
5 changed files with 161 additions and 0 deletions
54
prompt.lua
Normal file
54
prompt.lua
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
local function prompt_yn(question)
|
||||
while true do
|
||||
io.write(question .. " [y/N]: ")
|
||||
local input = io.read()
|
||||
if input == "y" or input == "Y" then
|
||||
return true
|
||||
end
|
||||
io.write("Exiting...\n")
|
||||
os.exit(1)
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
-- Run a command using the OS shell and capture the stdout
|
||||
-- Strips exactly one trailing newline if present, does not strip any other whitespace.
|
||||
-- Asserts that the command exits cleanly
|
||||
local function capture(command)
|
||||
local p = io.popen(command)
|
||||
local output = p:read("*a")
|
||||
assert(p:close())
|
||||
-- Strip exactly one trailing newline from the output, if there is one
|
||||
return output:match("(.-)\n$") or output
|
||||
end
|
||||
|
||||
local funct
|
||||
|
||||
local function append_list(list, other)
|
||||
for _, item in ipairs(other) do
|
||||
table.insert(list, item)
|
||||
end
|
||||
end
|
||||
|
||||
local function err(msg)
|
||||
io.stderr:write("Error: " .. msg .. "\n")
|
||||
end
|
||||
|
||||
local function fatal(msg)
|
||||
err(msg)
|
||||
os.exit(1)
|
||||
end
|
||||
|
||||
local demolist = { 1, 2, 3 }
|
||||
-- append_list(demolist, 4)
|
||||
|
||||
demolist[#demolist + 1] = 4
|
||||
|
||||
for _, value in ipairs(demolist) do
|
||||
print(value)
|
||||
end
|
||||
|
||||
print(capture("ls"))
|
||||
prompt_yn("Testing")
|
||||
err("Something bad happened")
|
||||
fatal("Crashing...")
|
||||
Loading…
Add table
Add a link
Reference in a new issue