Advertisement
apemanzilla

opdoc

Dec 2nd, 2015
1,209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.78 KB | None | 0 0
  1. local files = {
  2.     ["init"] = "require \"UIButton\"\
  3. require \"UIContainer\"\
  4. require \"UITabs\"\
  5. require \"UIText\"\
  6. \
  7. local function quit()\
  8.     application:stop() term.clear() term.setCursorPos(1,1) \
  9. end\
  10. \
  11. application.view:createShortcut(\"terminate\",\"ctrl-t\",quit)\
  12. local close = application.view:addChild(UIButton(application.view.width-1,0,1,1,\"X\"))\
  13. close.colour = colors.red\
  14. close.textColour = colors.black\
  15. close.onClick = quit\
  16. \
  17. local peripherals = peripheral.getNames()\
  18. \
  19. for i,v in ipairs(peripherals) do\
  20.     local p = peripheral.wrap(v)\
  21.     if not p.listMethods then\
  22.         table.remove(peripherals,i)\
  23.     end\
  24. end\
  25. \
  26. local tabs = application.view:addChild(UITabs(1,1,application.view.width-2,peripherals))\
  27. \
  28. local m_cont = application.view:addChild(UIContainer(1,3,application.view.width-2,application.view.height-4))\
  29. \
  30. local text_cont = UIContainer(1,3,application.view.width-2,application.view.height-4)\
  31. local back_btn = text_cont:addChild(UIButton(0,0,text_cont.width-1,1,\"Back\"))\
  32. back_btn.textColour = colors.red\
  33. \
  34. local m_texts = {}\
  35. \
  36. local function display_method(pname,mname)\
  37.     m_cont:remove()\
  38.     text_cont:remove()\
  39.     application.view:addChild(text_cont)\
  40.     for _,text in ipairs(m_texts) do\
  41.         text:remove()\
  42.     end\
  43.     local p = peripheral.wrap(pname)\
  44.     local m = p.getAdvancedMethodsData(mname)\
  45.     local y = 1\
  46.     local header = \"@tb\" .. mname .. \"(\"\
  47.     for i,v in ipairs(m.args) do\
  48.         if m.args[i+1] then\
  49.             header = header .. ((v.optional and \"@t9[\") or \"@t9\") .. v.name .. ((v.optional and \"]@t7, \") or \"@t7, \")\
  50.         else\
  51.             header = header .. ((v.optional and \"@t9[\") or \"@t9\") .. v.name .. ((v.optional and \"]\") or \"\")\
  52.         end\
  53.     end\
  54.     header = header .. \"@tb)\"\
  55.     local header_text = text_cont:addChild(UIText(0,y,text_cont.width-1,1,header))\
  56.     header_text.internalWidth = header_text.width - 1\
  57.     header_text.height = header_text:getContentHeight()\
  58.     table.insert(m_texts,header_text)\
  59.     y = y + header_text.height + 1\
  60. \
  61.     local desc = ((m.description ~= \"\" and m.description) or \"@t8<No description found>\")\
  62.     local desc_text = text_cont:addChild(UIText(1,y,text_cont.width-2,1,desc))\
  63.     desc_text.internalWidth = desc_text.width - 1\
  64.     desc_text.height = desc_text:getContentHeight()\
  65.     table.insert(m_texts,desc_text)\
  66.     y = y + desc_text.height + 1\
  67. \
  68.     if #m.args > 0 then\
  69.         local args_text = text_cont:addChild(UIText(0,y,text_cont.width-1,1,\"Arguments\"))\
  70.         args_text.internalWidth = args_text.width - 1\
  71.         args_text.height = args_text:getContentHeight()\
  72.         table.insert(m_texts,args_text)\
  73.         y = y + args_text.height + 1\
  74. \
  75.         for i,v in ipairs(m.args) do\
  76.             local arg = \"@t9\"..v.name..\"@t7: \" .. ((v.description ~= \"\" and v.description) or \"@t8<No description found>\")\
  77.             local arg_text = text_cont:addChild(UIText(1,y,text_cont.width-2,1,arg))\
  78.             arg_text.internalWidth = arg_text.width - 1\
  79.             arg_text.height = arg_text:getContentHeight()\
  80.             table.insert(m_texts,arg_text)\
  81.             y = y + arg_text.height\
  82.         end\
  83.         y = y + 1\
  84.     end\
  85.     if m.returnTypes ~= \"()\" then\
  86.         local ret = \"Returns @t9\" .. m.returnTypes\
  87.         local ret_text = text_cont:addChild(UIText(0,y,text_cont.width-1,1,ret))\
  88.         ret_text.internalWidth = ret_text.width - 1\
  89.         ret_text.height = ret_text:getContentHeight()\
  90.         table.insert(m_texts,ret_text)\
  91.         y = y + ret_text.height\
  92.     end\
  93.     text_cont:setVerticalOffset(0)\
  94. end\
  95. \
  96. local m_btns = {}\
  97. \
  98. local function show_method_buttons(pname)\
  99.     m_cont:remove()\
  100.     text_cont:remove()\
  101.     application.view:addChild(m_cont)\
  102.     local p = peripheral.wrap(pname)\
  103.     local m = (p.getAdvancedMethodsData and p.getAdvancedMethodsData()) or {}\
  104.     -- remove old children\
  105.     for _,btn in ipairs(m_btns) do\
  106.         btn:remove()\
  107.     end\
  108.     m_btns = {}\
  109.     -- add new buttons\
  110.     local ypos = 0\
  111.     for name,data in pairs(m) do\
  112.         local b = m_cont:addChild(UIButton(0,ypos,m_cont.width-1,1,name))\
  113.         function b:onClick()\
  114.             display_method(pname,name)\
  115.         end\
  116.         table.insert(m_btns,b)\
  117.         ypos = ypos + 1\
  118.     end\
  119.     m_cont:setVerticalOffset(0)\
  120. end\
  121. \
  122. function back_btn:onClick()\
  123.     show_method_buttons(peripherals[tabs.selected])\
  124. end\
  125. \
  126. function tabs:onSelect()\
  127.     show_method_buttons(peripherals[self.selected])\
  128. end";
  129. }
  130. if not fs.exists "Flare" then
  131.     print "Downloading Flare"
  132.     local h = http.get "http://pastebin.com/raw.php?i=SD25GhYf"
  133.     if h then
  134.         local f, err = load( h.readAll(), "installer", nil, _ENV or getfenv() )
  135.         h.close()
  136.         f()
  137.     else
  138.         return error( "Cannot install Flare", 0 )
  139.     end
  140. end
  141. local loader
  142. local h = fs.open( "Flare/run.lua", "r" )
  143. if h then
  144.     loader = h.readAll()
  145.     h.close()
  146. else
  147.     error( "failed to read Flare", 0 )
  148. end
  149. local f, err = load( loader, "Flare", nil, _ENV or getfenv() )
  150. if not f then
  151.     error( "there was a problem with Flare!: " .. err, 0 )
  152. end
  153. f( files, "init", ... )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement