Browse Source

added lib folder with some handy modules

utils a library for some handy library functions now constains ask
confirmation which takes a pre and post condition and asks you if
you want to continue.

Also a turtle module which allows you to test your code for syntax errors.
master
unknown 13 years ago
parent
commit
f530d034ad
  1. 18
      lib/turtlePlaceholder
  2. 17
      lib/utils
  3. 36
      makefloor

18
lib/turtlePlaceholder

@ -0,0 +1,18 @@
local function placeholder() return true end
local turtle = {}
turtle.up = placeholder
turtle.down = placeholder
turtle.digUp = placeholder
turtle.digDown = placeholder
turtle.dig = placeholder
turtle.forward = placeholder
turtle.turnLeft = placeholder
turtle.turnRight = placeholder
turtle.detect = placeholder
turtle.getItemCount = placeholder
turtle.placeDown = placeholder
turtle.select = placeholder
return turtle

17
lib/utils

@ -0,0 +1,17 @@
local function confirmExe(pre, post)
print("Pre:", pre)
print("Post:", post)
print("Do you want to continue Y/N [Y]: ")
local confirmation = io.stdin:read(1)
if (confirmation == 'n' or confirmation == 'N') then
print("Aborted")
return false
end
io.stdin:read("*a") -- clear stdin
end
local utils = {}
utils.confirmExecution = confirmExe
return utils

36
makefloor

@ -1,21 +1,10 @@
local args = { ... } local args = { ... }
--[[
local function placeholder() return true end package.path = package.path .. ";" .. "lib/?"
local turtle = {}
turtle.up = placeholder -- local turtle = require "turtlePlaceholder"
turtle.down = placeholder local utils = require "utils"
turtle.digUp = placeholder
turtle.digDown = placeholder
turtle.dig = placeholder
turtle.forward = placeholder
turtle.turnLeft = placeholder
turtle.turnRight = placeholder
turtle.detect = placeholder
turtle.getItemCount = placeholder
turtle.placeDown = placeholder
turtle.select = placeholder
]]
local turnedLeft = nil local turnedLeft = nil
if args[1] == "rightturn" or args[1] == "leftturn" then if args[1] == "rightturn" or args[1] == "leftturn" then
@ -25,7 +14,12 @@ else
return return
end end
print(turnedLeft) local pre = "A room with walls atleast 2 high and robot should start in a corner"
local post = "a room with a floor of $material"
if not utils.confirmExecution(pre, post) then
return
end
local curContainer = 1 local curContainer = 1
turtle.select(curContainer) turtle.select(curContainer)
@ -58,7 +52,6 @@ local function fillblock()
couldTurn = checkIfNextTurn() couldTurn = checkIfNextTurn()
end end
turtle.up()
if not selectMatStack() then if not selectMatStack() then
return false return false
end end
@ -72,8 +65,13 @@ local function fillblock()
else else
turtle.forward() turtle.forward()
end end
turtle.down()
return true return true
end end
while not detectDown() do
turtle.down()
end
turtle.up()
while fillblock() do end while fillblock() do end