BigSHinyToys

[Computer Craft].net api test

Jan 11th, 2013
179
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --[[
  2.     test for net
  3. ]]--
  4.  
  5. local function clear()
  6.     term.setBackgroundColor(colors.black)
  7.     term.setTextColor(colors.white)
  8.     term.clear()
  9.     term.setCursorPos(1,1)
  10. end
  11.  
  12. local function testOne()
  13.     clear()
  14.  
  15.     local win = net.newWindow()
  16.     local files
  17.     local path = {}
  18.  
  19.     local function sPath()
  20.         return table.concat(path,"/")
  21.     end
  22.  
  23.     local function newlist()
  24.         local test,this = pcall(fs.list,sPath())
  25.         return (this or {})
  26.     end
  27.  
  28.     local function goBack()
  29.         table.remove(path)
  30.         files("set",newlist())
  31.     end
  32.  
  33.     local function goForward(step)
  34.         table.insert(path,step)
  35.         files("set",newlist())
  36.     end
  37.    
  38.     local function kill()
  39.         win("kill")
  40.     end
  41.    
  42.     files = net.listBox(win,newlist(),goForward,1,3,40,10,"lightGray","gray")
  43.     net.button(win,"[back]",goBack,1,2,"lime","green")
  44.     net.button(win,"[return]",kill,8,2,"lime","green")
  45.  
  46.     net.run(win)
  47. end
  48.  
  49. local function testTwo()
  50.     clear()
  51.    
  52.     local function testC(...)
  53.         print("test C")
  54.         print(...)
  55.         error()
  56.     end
  57.  
  58.     term.clear()
  59.     term.setCursorPos(1,1)
  60.     local win = net.newWindow()
  61.     local list1 = net.listBox(win,{"option 1","options 2","options 3","options 4"},testC,2,6,10,10,"lightGray","gray")
  62.     local list2 = net.listBox(win,{"option 1","options 2","options 3","options 4"},testC,13,6,10,10,"lightGray","gray")
  63.     local list3 = net.listBox(win,{"option 1","options 2","options 3","options 4"},testC,24,6,10,10,"lightGray","gray")
  64.     local list4 = net.listBox(win,{"option 1","options 2","options 3","options 4"},testC,35,6,10,10,"lightGray","gray")
  65.  
  66.     local function testA()
  67.         list4("clear")
  68.     end
  69.  
  70.     local function testB()
  71.         list4("add","hello")
  72.     end
  73.    
  74.     local function kill()
  75.         win("kill")
  76.     end
  77.    
  78.     local button1 = net.button(win,"[button1]",testA,2,2,"lime","green")
  79.     local button2 = net.button(win,"[button2]",testB,2,4,"lime","green")
  80.     net.button(win,"[button4]",kill,12,4,"lime","green")
  81.    
  82.     local button3 -- needs to be declared before chicken or egg probblem
  83.     local count = 1
  84.     local function testC()
  85.         count = count + 1
  86.         button3("set","[click "..tostring(count).."]")
  87.     end
  88.     button3 = net.button(win,"[button3]",testC,12,2,"lime","green")
  89.  
  90.     net.run(win)
  91. end
  92.  
  93. local win = net.newWindow()
  94. local function kill()
  95.     win("kill")
  96. end
  97.  
  98. clear()
  99. net.button(win,"[button1]",testOne,2,2,"lime","green")
  100. net.button(win,"[button2]",testTwo,2,4,"lime","green")
  101. net.button(win,"[button3]",kill,2,6,"lime","green")
  102. net.run(win)
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×