Advertisement
Guest User

go

a guest
Jun 27th, 2014
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.75 KB | None | 0 0
  1. local shell = require ( 'shell' )
  2. local options = shell.parse ( ... )
  3.  
  4. local valid = {}
  5. valid = {
  6.   ['forward']  = function (a) valid ['_'](a) end,
  7.   ['back']     = function (a) valid ['_'](a) end,
  8.   ['up']       = function (a) valid ['_'](a) end,
  9.   ['down']     = function (a) valid ['_'](a) end,
  10.   ['left']     = function (a) for i=1,a do require('robot').turnLeft () end end,
  11.   ['right']    = function (a) for i=1,a do require ('robot').turnRight () end end,
  12.   ['_']        = function (a) for i=1,a do require('robot') [options[1]] () end end,
  13. }
  14.  
  15. if options[1] ~= '_' and valid [options[1]] then
  16.   valid [options[1]](tonumber(options[2]) or 1)
  17. else
  18.   io.write ( 'Usage: go direction [amount]\n' )
  19.   io.write ( 'Direction: forward,back,up,down,left or right\n' )
  20. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement