Advertisement
lignite0

LigCraftSoft - lig - v0.1

Aug 22nd, 2015
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.59 KB | None | 0 0
  1.  
  2. ----------------------------------------------------------------------------
  3. --------------------------------- HELPERS ----------------------------------
  4. ----------------------------------------------------------------------------
  5.  
  6. local function str2array(str)
  7.     local array = {}
  8.     for i = 1, #str do
  9.         array[i] = str:sub(i, i)
  10.     end
  11.     return array
  12. end
  13.  
  14. local turtleMoveFunction = {
  15.     f = turtle.forward,
  16.     b = turtle.back,
  17.     u = turtle.up,
  18.     d = turtle.down,
  19.     l = turtle.turnLeft,
  20.     r = turtle.turnRight,
  21. }
  22.  
  23. ----------------------------------------------------------------------------
  24. --------------------------------- PROGRAMS ---------------------------------
  25. ----------------------------------------------------------------------------
  26.  
  27. local programs = {
  28.     help = function(args)
  29.         print("Usage: lig <program> [param, [...]]")
  30.     end,
  31.    
  32.     m = function(args)
  33.         if #args < 1 then
  34.             print("Usage: lig m <path>")
  35.             return
  36.         end
  37.         for node in string.gmatch(args[1], "[a-z][0-9]*") do
  38.             local direction = string.sub(node, 1, 1)
  39.             local length = string.sub(node, 2)
  40.             if turtleMoveFunction[direction] == nil then
  41.                 print("Error: Undefined direction!")
  42.                 return
  43.             end    
  44.             if not length then
  45.                 length = 1
  46.             end        
  47.             for i = 1, length, 1 do
  48.                 breakCount = 30
  49.                 while (not turtleMoveFunction[direction]) and breakCount > 0 do
  50.                     sleep(0.1)
  51.                     breakCount = breakCount - 1;
  52.                 end
  53.             end
  54.         end
  55.     end
  56. }
  57.  
  58. ----------------------------------------------------------------------------
  59. ----------------------------------- ARGS -----------------------------------
  60. ----------------------------------------------------------------------------
  61.  
  62. local function execArgs(args)
  63.  
  64.     local program = "help"
  65.  
  66.     if #args >= 1 then
  67.         program = table.remove(args, 1)
  68.     end
  69.  
  70.     if programs[program] ~= nil then
  71.         print("Executing program: "..program)
  72.         programs[program](args)
  73.         print("Executed.")
  74.     else
  75.         print('Not found program!');
  76.         return;
  77.     end
  78. end
  79.  
  80. ----------------------------------------------------------------------------
  81. ----------------------------------- MAIN -----------------------------------
  82. ----------------------------------------------------------------------------
  83.  
  84. print("LigCraftSoft - lig - v0.1");
  85.  
  86. local args = {...}
  87. execArgs(args);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement