-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathredstone.lua
More file actions
71 lines (57 loc) · 1.99 KB
/
redstone.lua
File metadata and controls
71 lines (57 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
local syscall = require "_syscall"
local expect = require "cc.expect"
local redstone = {}
function redstone.getSides()
return syscall.devchildren("/redstone")
end
function redstone.getInput(side)
expect(1, side, "string")
return syscall.devcall("/redstone/" .. side, "getInput") > 0
end
function redstone.getOutput(side)
expect(1, side, "string")
return syscall.devcall("/redstone/" .. side, "getOutput") > 0
end
function redstone.setOutput(side, value)
expect(1, side, "string")
expect(2, value, "boolean")
return syscall.devcall("/redstone/" .. side, "setOutput", value and 15 or 0)
end
function redstone.getAnalogInput(side)
expect(1, side, "string")
return syscall.devcall("/redstone/" .. side, "getInput")
end
function redstone.getAnalogOutput(side)
expect(1, side, "string")
return syscall.devcall("/redstone/" .. side, "getOutput")
end
function redstone.setAnalogOutput(side, value)
expect(1, side, "string")
expect(2, value, "number")
expect.range(value, 0, 15)
return syscall.devcall("/redstone/" .. side, "setOutput", value)
end
function redstone.getBundledInput(side)
expect(1, side, "string")
return syscall.devcall("/redstone/" .. side, "getBundledInput")
end
function redstone.getBundledOutput(side)
expect(1, side, "string")
return syscall.devcall("/redstone/" .. side, "getBundledOutput")
end
function redstone.setBundledOutput(side, value)
expect(1, side, "string")
expect(2, value, "number")
expect.range(value, 0, 65535)
return syscall.devcall("/redstone/" .. side, "setBundledOutput", value)
end
function redstone.testBundledInput(side, mask)
expect(1, side, "string")
expect(2, mask, "number")
expect.range(mask, 0, 65535)
return bit32.band(syscall.devcall("/redstone/" .. side, "getBundledInput"), mask) == mask
end
redstone.getAnalogueInput = redstone.getAnalogInput
redstone.getAnalogueOutput = redstone.getAnalogOutput
redstone.setAnalogueOutput = redstone.setAnalogOutput
return redstone