dofile instead of require etc
authorOlav Bakke Svendsen <mail@olavbs.no>
Wed, 15 May 2024 17:58:12 +0000 (19:58 +0200)
committerOlav Bakke Svendsen <mail@olavbs.no>
Wed, 15 May 2024 17:58:12 +0000 (19:58 +0200)
lib/turtle-utils.lua
vineyard/turtle/harvest.lua
vineyard/turtle/package

index 081acb1ab4a85a64c8a28f605b5869d32afb3d34..b860555f861025355ec9e5940d12d7accf112366 100644 (file)
@@ -24,10 +24,12 @@ local oneOf = function(t, a)
 end
 --------------------------------------
 
+local lib = {}
+
 -- findItem : list of item names -> index | false message
 -- returns the first inventory index containing an item from list t
 -- if no item is found, returns nil
-local findItem = function(t)
+lib.findItem = function(t)
   for i = 1, 16 do
     local item = turtle.getItemDetail(i)
     if item and oneOf(t, item.name) then return i end
@@ -38,7 +40,7 @@ end
 -- findEmpty : index | false message
 -- returns the first empty slot
 -- if no empty slot is found, returns nil
-local findEmpty = function()
+lib.findEmpty = function()
   for i = 1, 16 do if not turtle.getItemDetail(i) then return i end end
   return false, "No empty slot"
 end
@@ -46,7 +48,7 @@ end
 -- count : list of item names -> count
 -- counts how many slots contain an item from list t
 -- (does not count individual items)
-local count = function(t)
+lib.count = function(t)
   local c = 0
   for i = 1, 16 do
     local item = turtle.getItemDetail(i)
@@ -60,7 +62,7 @@ end
 -- selectItem : list of item names -> true | false message
 -- select first slot containing an item from list t if not already selected.
 -- returns bool.
-local selectItem = function(t)
+lib.selectItem = function(t)
   local item = turtle.getItemDetail()
   if item and oneOf(t, item.name) then
     return true
@@ -78,7 +80,7 @@ end
 -- like selectItem, selects item from list, but tries to move it to the first slot.
 -- requires an empty slot to move items around.
 -- (this function exists because weak automata cannot digBlock with tools in slots >9)
-local transferAndSelect = function(i, t)
+lib.transferAndSelect = function(i, t)
   if i < 1 or i > 16 then return false, msg .. "Index out of range" end
   -- if a wanted item already is in the wanted slot, select it and return early
   local item = turtle.getItemDetail(i)
@@ -116,7 +118,7 @@ end
 -- "u1 5r" = invalid
 
 -- commandMap : t f
-local commandMap =
+lib.commandMap =
   { ["u"] = turtle.up
   , ["d"] = turtle.down
   , ["f"] = turtle.forward
@@ -126,19 +128,19 @@ local commandMap =
   }
 
 -- runStringCommand : string -> true | false message
-local runCommandString = function(str, map)
+lib.runStringCommand = function(str, map)
   local c, n, rest = string.match(string.gsub(str, "^%s+", ""), "^(%w)(%d*)(.*)")
   if not c then return true end
   if n == "" then n = 1 else n = tonumber(n) end
   for i = 1, n do map[c]() end
 --     print(cmd, tostring(i).."/"..tostring(n))
 --   end
-  return turtle.runCommandString(rest)
+  return lib.runStringCommand(rest)
 end 
 
 -- rep : number of repeats -> string -> string | nil
 -- repeats string n times
-local rep = function(n, str)
+lib.rep = function(n, str)
   if not n or n < 0 then return nil end
   local s = ""
   for i = 1, n do
@@ -146,3 +148,5 @@ local rep = function(n, str)
   end
   return s
 end
+
+return lib
index c57a9c0d2b1954319dab7f7a326e6b8d005aa4a0..c5bbea12f735d30bc20a0cc0ecfd3c9ac705e829 100644 (file)
@@ -10,7 +10,7 @@
 -- index
 -- repeat
 
-local tu = require("lib/turtle-utils.lua")
+local tu = dofile("/lib/turtle-utils.lua")
 local automata = peripheral.wrap("left")
 
 local shears =
index b62febb861c22dd1396a69f47e9ba4ede7edba5b..5b91eeeea3b8fc0ed336d214f98b1dfe91eeffa8 100644 (file)
@@ -1,2 +1,2 @@
-lib/turtle-utils.lua:/lib/turle-utils.lua:o
-vineyard/turtle/harvest.lua:/bin/harvest.lua:o
+cc lib/turtle-utils.lua:/lib/turtle-utils.lua:o
+cc vineyard/turtle/harvest.lua:/bin/harvest.lua:o