-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
36 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters