Homogenize scripts a little.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
local args = table.pack(...)
|
||||
if #args == 0 then
|
||||
io.write("Usage:\n")
|
||||
io.write(" redstone <side name> [<value>]\n")
|
||||
return
|
||||
if #arg == 0 then
|
||||
io.write("Usage: redstone.lua side [value]\n")
|
||||
os.exit(1)
|
||||
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 function set_of(...)
|
||||
local set = {}
|
||||
for _, value in pairs(table.pack(...)) do
|
||||
set[value] = true
|
||||
end
|
||||
return set
|
||||
end
|
||||
|
||||
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")
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user