-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathright.lua
45 lines (45 loc) · 982 Bytes
/
right.lua
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
local args = {...}
local term = require("term")
local robot = require("robot")
local sh = require("shell")
local function println(s)
if s then
term.write(s.."\n")
else
term.write("\n")
end
end
local function printUsage()
local name = debug.getinfo(2,"S").short_src:match("[^/]+.lua$")
if name then
name = name:sub(0,-5)
else
name = "right"
end
println("Usage:")
println(name.." <d>")
println("d: Number of spaces to move right")
os.exit()
end
local d
if #args==0 then
d = 1
else
if #args~=1 then
println("Incorrect number of arguments.")
printUsage()
end
d = tonumber(args[1])
if d==nil then
println("Failed to convert argument to number.")
printUsage()
elseif d<=0 then
println("Please provide a positive argument.")
printUsage()
end
end
robot.turnRight()
println("Turned right.")
sh.execute(debug.getinfo(2,"S").short_src:gsub("[^/]*.lua$","").."forward.lua "..d)
robot.turnLeft()
println("Turned left.")