Skip to content

Commit

Permalink
Homogenize scripts a little.
Browse files Browse the repository at this point in the history
  • Loading branch information
fnuecke committed Jan 10, 2022
1 parent 4ff68cd commit 3407e84
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 35 deletions.
6 changes: 3 additions & 3 deletions src/main/scripts/bin/export.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ local devices = require("devices")
local device = devices:find("file_import_export")

if not device then
io.write("A File Import/Export Card is required for this functionality.\n")
return
io.stderr:write("A File Import/Export Card is required for this functionality.\n")
os.exit(1)
end

if not arg[1] then
if #arg == 0 then
io.write("Usage: export.lua filename\n")
os.exit(1)
end
Expand Down
4 changes: 2 additions & 2 deletions src/main/scripts/bin/import.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ local devices = require("devices")
local device = devices:find("file_import_export")

if not device then
io.write("A File Import/Export Card is required for this functionality.\n")
return
io.stderr:write("A File Import/Export Card is required for this functionality.\n")
os.exit(1)
end

device:reset()
Expand Down
57 changes: 29 additions & 28 deletions src/main/scripts/bin/redstone.lua
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
#!/usr/bin/lua

local devices = require('devices')

local rs = devices:find("redstone")

if not rs then
io.stderr:write("This program requires a Redstone Interface Card or Redstone Interface.\n")
return 1
io.stderr:write("This program requires a Redstone Interface Block or Card.\n")
os.exit(1)
end

if #arg == 0 then
io.write("Usage: redstone.lua side [value]\n")
os.exit(1)
end

local args = table.pack(...)
if #args == 0 then
io.write("Usage:\n")
io.write(" redstone <side name> [<value>]\n")
return
local function set_of(...)
local set = {}
for _, value in pairs(table.pack(...)) do
set[value] = true
end
return set
end

if #args > 0 then
local side = string.lower(args[1])
sides = {["up"]=true,["down"]=true,["north"]=true,["south"]=true,["west"]=true,["east"]=true,
["front"]=true,["back"]=true,["left"]=true,["right"]=true}
if not sides[side] then
io.stderr:write("invalid side\n")
return
end

local value = args[2]
if value then
if tonumber(value) then
value = tonumber(value)
else
value = ({["true"]=true,["on"]=true,["yes"]=true})[value] and 15 or 0
end
rs:setRedstoneOutput(side, value)
end
io.write("in: " .. math.ceil(rs:getRedstoneInput(side)) .. "\n")
io.write("out: " .. math.ceil(rs:getRedstoneOutput(side)) .. "\n")
local side = string.lower(arg[1])
local sides = set_of("up", "down", "north", "south", "west", "east", "front", "back", "left", "right")
if not sides[side] then
io.stderr:write("Invalid side argument.\n")
os.exit(1)
end

local value = arg[2]
if value then
local on = set_of("true", "on", "yes")
value = tonumber(value) or on[value] and 15 or 0
rs:setRedstoneOutput(side, value)
end

io.write("in: " .. math.ceil(rs:getRedstoneInput(side)) .. "\n")
io.write("out: " .. math.ceil(rs:getRedstoneOutput(side)) .. "\n")
4 changes: 2 additions & 2 deletions src/main/scripts/bin/setup-network.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ if dhcpServer == "y" or dhcpServer == "Y" then
end

if not dhcpRangeStart:match("%d+%.%d+%.%d+%.%d+") then
io.write("Invalid IP address format.")
io.stderr:write("Invalid IP address format.")
else
break
end
Expand All @@ -90,7 +90,7 @@ if dhcpServer == "y" or dhcpServer == "Y" then
end

if not dhcpRangeEnd:match("%d+%.%d+%.%d+%.%d+") then
io.write("Invalid IP address format.")
io.stderr:write("Invalid IP address format.")
else
break
end
Expand Down

0 comments on commit 3407e84

Please sign in to comment.