Advertisement
billysback

MenuX

Nov 8th, 2012
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 37.23 KB | None | 0 0
  1.  
  2. local lastlog = ""
  3.  
  4. local interactions = {}
  5. local selected = nil
  6.  
  7. local vars = {}
  8.  
  9. local funcs = {}
  10.  
  11. local startup = {}
  12. local oevent = {}
  13. local updte = {}
  14.  
  15. local cols = {}
  16.  
  17. local on = true
  18.  
  19. local blk = true
  20.  
  21. local function setPixel(x, y, color)
  22.     local oldx, oldy = term.getCursorPos()
  23.     term.setCursorPos(x, y)
  24.     term.setBackgroundColor(color)
  25.     term.setCursorPos(oldx, oldy)
  26.     if cols[x] == nil then
  27.         cols[x] = {}
  28.     end
  29.     cols[x][y] = color
  30. end
  31.  
  32. local function setPixelText(x, y, color)
  33.     local oldx, oldy = term.getCursorPos()
  34.     term.setCursorPos(x, y)
  35.     term.setTextColor(color)
  36.     term.setCursorPos(oldx, oldy)
  37.     if cols[x] == nil then
  38.         cols[x] = {}
  39.     end
  40.     cols[x][y] = color
  41. end
  42.  
  43. local function getSetColour(x, y)
  44.     local color = colors.black
  45.     if cols[x] ~= nil then
  46.         local xtab = cols[x]
  47.         if xtab[y] ~= nil then
  48.             color = xtab[y]
  49.         end
  50.     end
  51.     return color
  52. end
  53.  
  54. local function getColour(color)
  55.     color = string.lower(color)
  56.     if color == "white" then
  57.         return colors.white
  58.     elseif color == "orange" then
  59.         return colors.orange
  60.     elseif color == "magenta" then
  61.         return colors.magenta
  62.     elseif color == "lightblue" then
  63.         return colors.lightblue
  64.     elseif color == "yellow" then
  65.         return colors.yellow
  66.     elseif color == "lime" then
  67.         return colors.lime
  68.     elseif color == "pink" then
  69.         return colors.pink
  70.     elseif color == "gray" then
  71.         return colors.gray
  72.     elseif color == "lightgray" then
  73.         return colors.lightgray
  74.     elseif color == "cyan" then
  75.         return colors.cyan
  76.     elseif color == "purple" then
  77.         return colors.purple
  78.     elseif color == "blue" then
  79.         return colors.blue
  80.     elseif color == "brown" then
  81.         return colors.brown
  82.     elseif color == "green" then
  83.         return colors.green
  84.     elseif color == "red" then
  85.         return colors.red
  86.     elseif color == "black" then
  87.         return colors.black
  88.     else
  89.         return colors.white
  90.     end
  91. end
  92.  
  93. local function containsKey(tab, key)
  94.     for i=1,#tab do
  95.         local var = tab[i]
  96.         if var[1] == key then
  97.             return true
  98.         end
  99.     end
  100.     return false
  101. end
  102.  
  103. local function setValue(tab, key, value)
  104.     for i=1,#tab do
  105.         local var = tab[i]
  106.         if var[1] == key then
  107.             var[2] = value
  108.         end
  109.     end
  110. end
  111.  
  112. local function getValue(tab, key)
  113.     for i=1,#tab do
  114.         local var = tab[i]
  115.         if var[1] == key then
  116.             return var[2]
  117.         end
  118.     end
  119.     return nil
  120. end
  121.  
  122. local function putValue(tab, key, value)
  123.     tab[#tab + 1] = {key, value}
  124. end
  125.  
  126. local function delValue(tab, key)
  127.     local nval = {}
  128.     for i=1,#tab do
  129.         local var = tab[i]
  130.         if var[1] == key then else
  131.             nval[#nval + 1] = var
  132.         end
  133.     end
  134.     vars = nval
  135. end
  136.  
  137. local function split(str, pat)
  138.     local t = {}  -- NOTE: use {n = 0} in Lua-5.0
  139.     if str ~= nil then
  140.        local fpat = "(.-)" .. pat
  141.        local last_end = 1
  142.        local s, e, cap = str:find(fpat, 1)
  143.        while s do
  144.           if s ~= 1 or cap ~= "" then
  145.          table.insert(t,cap)
  146.           end
  147.           last_end = e+1
  148.           s, e, cap = str:find(fpat, last_end)
  149.        end
  150.        if last_end <= #str then
  151.           cap = str:sub(last_end)
  152.           table.insert(t, cap)
  153.        end
  154.     else
  155.         print("##3DD ERROR failed to split ["..str.."] by:"..pat)
  156.     end
  157.     return t
  158. end
  159.  
  160. local function setLog(lg)
  161.     lastlog = lg
  162.     term.setCursorPos(1,1)
  163.     term.write(" [ERROR: "..lg.."]")
  164. end
  165.  
  166. local function getStr(v)
  167.     local value = v
  168.     if string.sub(value, 1, 1) == '"'  then
  169.         if string.sub(value, -1, -1) == '"' then
  170.             if string.len(value) > 2 then
  171.                 value = string.sub(value, 2, -2)
  172.             else
  173.                 value = ""
  174.             end
  175.         else
  176.             return {false, "UNF STRING"}
  177.         end
  178.     end
  179.     return {true, value}
  180. end
  181.  
  182. local function getInt(v)
  183.     local value = v
  184.     if string.sub(value, 1, 1) == "#" then
  185.         if string.len(value) > 1 then
  186.             local sn = string.sub(value, 2, -1)
  187.             if string.sub(sn, 1, 3) == "RND" then
  188.                 if string.len(sn) > 3 then
  189.                     local splt = split(sn, "~")
  190.                     if #splt == 2 then
  191.                         local v1 = tonumber(splt[2])
  192.                         if v1 ~= nil then
  193.                             value = math.random(v1)
  194.                         else
  195.                             return {false, "INVALID RND"}
  196.                         end
  197.                     elseif #splt == 3 then
  198.                         local v1 = tonumber(splt[2])
  199.                         local v2 = tonumber(splt[3])
  200.                         if v1 ~= nil and v2 ~= nil then
  201.                             value = math.random(v1, v2)
  202.                         else
  203.                             return {false, "INVALID RND"}
  204.                         end
  205.                     else
  206.                         return {false, "INVALID RND"}
  207.                     end
  208.                 else
  209.                     value = math.random()
  210.                 end
  211.             elseif tonumber(sn) ~= nil then
  212.                 value = tonumber(sn)
  213.             else
  214.                 return {false, "INVALID VALUE"}
  215.             end
  216.         else
  217.             return {false, "NO INT GIVEN"}
  218.         end
  219.     end
  220.     return {true, value}
  221. end
  222.  
  223. local function getOVal(v)
  224.     local value = v
  225.     if string.sub(value, 1, 1) == '$' then
  226.         if string.len(value) > 1 then
  227.             local nv = string.sub(value, 2, -1)
  228.             if containsKey(vars, nv) then
  229.                 value = getValue(vars, nv)
  230.             else
  231.                 return {false, "NONEXISTANT VAR"}
  232.             end
  233.         else
  234.             return {false, "NO VALUE GIVEN"}
  235.         end
  236.     end
  237.     return {true, value}
  238. end
  239.  
  240. local function getTabl(v)
  241.     local value = string.lower(v)
  242.     if string.sub(value, 1, 1) == "<" and string.sub(value, 1, 1) == ">" then
  243.         local splt = split(value, "|")
  244.         local tabl = {}
  245.         for i=1,#splt do
  246.             tabl[#tabl + 1] = getVal(splt[i])
  247.         end
  248.         value = tabl
  249.     end
  250.     return value
  251. end
  252.  
  253. local function getBool(v)
  254.     local value = string.lower(v)
  255.     if string.sub(value, 1, 1) == "%" then
  256.         local yn = string.sub(2,-1)
  257.         if yn == "y" or yn == "yes" or yn == "t" or yn == "true" or yn == "1" then
  258.             value = true
  259.         elseif yn == "n" or yn == "no" or yn == "f" or yn == "false" or yn == "0" then
  260.             value = false
  261.         else
  262.             return {false, "INVALID BOOLEAN"}
  263.         end
  264.     end
  265.     return {true, value}
  266. end
  267.  
  268. function getVal(v)
  269.     local value = v
  270.     local done = false
  271.    
  272.     local vres1 = getStr(value)
  273.     if vres1[1] then
  274.         local oval = value
  275.         value = vres1[2]
  276.         if oval ~= value then done = true end
  277.     else return {false, vres1[2]} end
  278.    
  279.     if not done then
  280.         local vres2 = getInt(value)
  281.         if vres2[1] then
  282.             local oval = value
  283.             value = vres2[2]
  284.             if oval ~= value then done = true end
  285.         else return {false, vres2[2]} end
  286.     end
  287.    
  288.     if not done then
  289.         local vres3 = getOVal(value)
  290.         if vres3[1] then
  291.             local oval = value
  292.             value = vres3[2]
  293.             if oval ~= value then done = true end
  294.         else return {false, vres3[2]} end
  295.     end
  296.    
  297.     if not done then
  298.         local vres3 = getBool(value)
  299.         if vres3[1] then
  300.             local oval = value
  301.             value = vres3[2]
  302.             if oval ~= value then done = true end
  303.         else return {false, vres3[2]} end
  304.     end
  305.    
  306.     return {true, value}
  307. end
  308.  
  309. local function doFunc(ds, dn)
  310.     if containsKey(ds, dn) then
  311.         local code = getValue(ds, dn)
  312.         if not runC(code, 0, nil) then return {false, lastlog} end
  313.     else
  314.         return {false, "NONEXISTANT CODE "..(string.upper(dn).." ")}
  315.     end
  316.     return {true, ""}
  317. end
  318.  
  319. local function ifFunc(ds, splt, is)
  320.     local vals = {}
  321.  
  322.     local curi = 2
  323.     local ison = true
  324.     while splt[curi] ~= "DO" and ison do
  325.         local val1 = nil
  326.    
  327.         local vtab1 = getVal(splt[curi])
  328.         if vtab1[1] then val1 = vtab1[2] else return {false, vtab1[2]} end
  329.        
  330.         vals[#vals + 1] = val1
  331.        
  332.         curi = curi + 1
  333.         if #splt < curi then ison = false end
  334.     end
  335.    
  336.     if not ison then return {false, "NO END OF IF"} end
  337.    
  338.     if #vals < 2 then return {false, "NOT ENOUGH VALS"} end
  339.    
  340.     local isok = true
  341.     for j=1,#vals do
  342.         local k = j+1
  343.         if k > #vals then k = 1 end
  344.        
  345.         if is then
  346.             if vals[j] == vals[k] then else isok = false end
  347.         else
  348.             if vals[j] ~= vals[k] then else isok = false end
  349.         end
  350.     end
  351.    
  352.     if isok then
  353.         local dn = splt[ #splt ]
  354.         local result = doFunc(ds, dn)
  355.         if not result[1] then return {false, result[2]} else return {true, true} end
  356.     else
  357.         return {true, false}
  358.     end
  359. end
  360.  
  361. local function doMath(val1, val2, sep)
  362.     local eval = val1
  363.     if sep == "+" then
  364.         eval = val1 + val2
  365.     elseif sep == "-" then
  366.         eval = val1 - val2
  367.     elseif sep == "/" then
  368.         eval = val1 / val2
  369.     elseif sep == "*" then
  370.         eval = val1 * val2
  371.     elseif sep == "^" then
  372.         eval = val1 ^ val2
  373.     end
  374.     return eval
  375. end
  376.  
  377. local function runCode(code, args)
  378.     local parts = code
  379.    
  380.     local ds = {}
  381.     local kon = false
  382.     local cdn = nil
  383.     local cd = {}
  384.     local curf = {}
  385.    
  386.     for i=1,#parts do
  387.         local part = parts[i]
  388.         local splt = split(part, " ")
  389.         if string.sub(part, 1, 2) == "##" or string.gsub(part, " ", "") == "" or part == "" then else
  390.             if not kon then
  391.                 local key = splt[1]
  392.                 if key == "DEF" then
  393.                     local name = splt[2]
  394.                     local value = splt[3]
  395.                    
  396.                     if string.sub(value, 1, 1) == '"' and #splt > 3 then
  397.                         for j=4,#splt do
  398.                             value = value.." "..splt[j]
  399.                         end
  400.                     end                
  401.                    
  402.                     local vtab = getVal(value)
  403.                     if vtab[1] then value = vtab[2] else return {vtab[2], i} end
  404.                    
  405.                     if containsKey(vars, name) then
  406.                         setValue(vars, name, value)
  407.                     else
  408.                         putValue(vars, name, value)
  409.                     end
  410.                 elseif key == "DEL" then
  411.                     local name = splt[2]
  412.                     if containsKey(vars, name) then
  413.                         delValue(vars, name)
  414.                     else
  415.                         return {"NONEXISTANT VAR", i}
  416.                     end
  417.                 elseif key == "SET" then
  418.                     local name = splt[2]
  419.                     local value = splt[3]
  420.                    
  421.                     if string.sub(value, 1, 1) == '"' and #splt > 3 then
  422.                         for j=4,#splt do
  423.                             value = value.." "..splt[j]
  424.                         end
  425.                     end
  426.                    
  427.                     local vtab = getVal(value)
  428.                     if vtab[1] then value = vtab[2] else return {vtab[2], i} end
  429.                    
  430.                     if containsKey(vars, name) then
  431.                         setValue(vars, name, value)
  432.                     else
  433.                         return {"NONEXISTANT VAR", i}
  434.                     end
  435.                 elseif key == "API" then
  436.                     local dir = splt[2]
  437.                     if #splt > 2 then
  438.                         for i=3,#splt do
  439.                             dir = dir.." "..splt[i]
  440.                         end
  441.                     end
  442.                    
  443.                     if fs.exists(dir) then
  444.                         loadMenu(dir)
  445.                     else
  446.                         return {"NONEXISTANT API FILE", i}
  447.                     end
  448.                 elseif key == "PRS" then
  449.                     local name = splt[2]
  450.                     if containsKey(funcs, name) then
  451.                         local func = getValue(funcs, name)
  452.                         if not runC(func, i) then return {"ERROR IN CODE", i} end
  453.                     else
  454.                         return {"NONEXISTANT FUNC", i}
  455.                     end
  456.                 elseif key == "RUN" then
  457.                     local name = splt[2]
  458.                     if #splt > 2 then
  459.                         local args = {}
  460.                         for i=3,#splt do
  461.                             args[#args + 1] = splt[i]
  462.                         end
  463.                         shell.run(name, args)
  464.                     else
  465.                         shell.run(name)
  466.                     end
  467.                 elseif key == "RUNLN" then
  468.                     local value = splt[2]
  469.                    
  470.                     if string.sub(value, 1, 1) == '"' and #splt > 3 then
  471.                         for j=4,#splt do
  472.                             value = value.." "..splt[j]
  473.                         end
  474.                     end                
  475.                    
  476.                     local vtab = getVal(value)
  477.                     if vtab[1] then value = vtab[2] else return {vtab[2], i} end
  478.                    
  479.                     if not runC({value}, i) then return {"ERROR IN CODE LINE", i} end
  480.                 elseif key == "DO" then
  481.                     local dn = splt[2]
  482.                     if containsKey(ds, dn) then
  483.                         local code = getValue(ds, dn)
  484.                         if not runC(code, i) then return {"ERROR IN CODE", i} end
  485.                     else
  486.                         return {"NONEXISTANT CODE", i}
  487.                     end
  488.                 elseif key == "IF" then
  489.                     local result = ifFunc(ds, splt, true)
  490.                     if not result[1] then return {result[2], i} end
  491.                 elseif key == "IFNOT" then
  492.                     local result = ifFunc(ds, splt, false)
  493.                     if not result[1] then return {result[2], i} end
  494.                 elseif key == "FOR" then
  495.                     local val1 = nil
  496.                     local vtab1 = getVal(splt[2])
  497.                     if vtab1[1] then val1 = vtab1[2] else return {vtab1[2], i} end
  498.                    
  499.                     local val2 = nil
  500.                     local vtab2 = getVal(splt[3])
  501.                     if vtab2[1] then val2 = vtab2[2] else return {vtab2[2], i} end
  502.                    
  503.                     local val3 = nil
  504.                     local vtab3 = getVal(splt[4])
  505.                     if vtab3[1] then val3 = vtab3[2] else return {vtab3[2], i} end
  506.                    
  507.                     local cdname = splt[5]
  508.                    
  509.                    
  510.                     if val1 ~= nil and val2 ~= nil and val3 ~= nil then
  511.                         for i=val1,val2,val3 do
  512.                             local result = doFunc(ds, cdname)
  513.                             if not result[1] then return {result[2], i} end
  514.                         end
  515.                     else
  516.                         return {"FOUND NULL", i}
  517.                     end
  518.                 elseif key == "WHILE" then
  519.                     local result = ifFunc(ds, splt, true)
  520.                     local canGo = true
  521.                     if not result[1] then
  522.                         canGo = false
  523.                         return {result[2], i}
  524.                     else
  525.                         canGo = result[2]
  526.                     end
  527.                    
  528.                     while canGo do
  529.                         local result = ifFunc(ds, splt)
  530.                         local canGo = true
  531.                         if not result[1] then
  532.                             canGo = false
  533.                             return {result[2], i}
  534.                         else
  535.                             canGo = result[2]
  536.                         end
  537.                     end
  538.                 elseif key == "ART" then
  539.                     if term.isColor() then
  540.                         local cmd = splt[2]
  541.                         color = getColour(color)
  542.                         if cmd == "BACKGROUND" then
  543.                             local color = splt[3]
  544.                            
  545.                             local vtab = getVal(color)
  546.                             if vtab1[1] then color = vtab1[2] else return {vtab1[2], i} end
  547.                            
  548.                             local x = splt[4]
  549.                             local y = splt[5]
  550.                            
  551.                             local vtab1 = getVal(x)
  552.                             if vtab1[1] then x = vtab1[2] else return {vtab1[2], i} end
  553.                             local vtab2 = getVal(y)
  554.                             if vtab1[1] then y = vtab1[2] else return {vtab1[2], i} end
  555.                            
  556.                             setPixel(x, y, color)
  557.                         elseif cmd == "TEXT" then
  558.                             local color = splt[3]
  559.                            
  560.                             local x = splt[4]
  561.                             local y = splt[5]
  562.                            
  563.                             local vtab1 = getVal(x)
  564.                             if vtab1[1] then x = vtab1[2] else return {vtab1[2], i} end
  565.                             local vtab1 = getVal(y)
  566.                             if vtab1[1] then y = vtab1[2] else return {vtab1[2], i} end
  567.                            
  568.                             setTextPixel(x, y, color)
  569.                         elseif cmd == "COLOR" or cmd == "COLOUR" then
  570.                             local result = splt[3]
  571.                             local color = splt[4]
  572.                             if containsKey(vars, result) then
  573.                                 setValue(vars, result, getColour(color))
  574.                             else
  575.                                 return {"NONEXISTANT VAR", i}
  576.                             end
  577.                         elseif cmd == "GET" then
  578.                             local result = splt[3]
  579.                            
  580.                             local x = splt[4]
  581.                             local y = splt[5]
  582.                            
  583.                             local vtab1 = getVal(x)
  584.                             if vtab1[1] then x = vtab1[2] else return {vtab1[2], i} end
  585.                             local vtab1 = getVal(y)
  586.                             if vtab1[1] then y = vtab1[2] else return {vtab1[2], i} end
  587.                            
  588.                             if containsKey(vars, result) then
  589.                                 setValue(vars, result, getSetColour(x, y))
  590.                             else
  591.                                 return {"NONEXISTANT VAR", i}
  592.                             end
  593.                         end
  594.                     else
  595.                         return {"NON-COLOR COMPUTER", i}
  596.                     end
  597.                 elseif key == "WHILENOT" then
  598.                     local result = ifFunc(ds, splt, false)
  599.                     local canGo = true
  600.                     if not result[1] then
  601.                         canGo = false
  602.                         return {result[2], i}
  603.                     else
  604.                         canGo = result[2]
  605.                     end
  606.                    
  607.                     while canGo do
  608.                         local result = ifFunc(ds, splt)
  609.                         local canGo = true
  610.                         if not result[1] then
  611.                             canGo = false
  612.                             return {result[2], i}
  613.                         else
  614.                             canGo = result[2]
  615.                         end
  616.                     end
  617.                 elseif key == "TABLE" then
  618.                     local cmd = splt[2]
  619.                     local name = splt[3]
  620.                     if containsKey(vars, name) then
  621.                         local tabl = getValue(vars, name)
  622.                        
  623.                         if cmd == "LEN" then
  624.                             local setto = splt[4]
  625.                             if containsKey(vars, setto) then
  626.                                 setValue(vars, setto, #tabl)
  627.                             else
  628.                                 putValue(vars, setto, #tabl)
  629.                             end
  630.                         else
  631.                             local index = splt[4]
  632.                            
  633.                             local vtab1 = getVal(index)
  634.                             if vtab1[1] then index = vtab1[2] else return {vtab1[2], i} end
  635.                            
  636.                             if cmd == "SET" then
  637.                                 local setto = splt[5]
  638.                                 local vtab1 = getVal(setto)
  639.                                 if vtab1[1] then setto = vtab1[2] else return {vtab1[2], i} end
  640.                                
  641.                                 if string.sub(setto, 1, 1) == '"' and #splt > 3 then
  642.                                     for j=4,#splt do
  643.                                         setto = setto.." "..splt[j]
  644.                                     end
  645.                                 end
  646.  
  647.                                 tabl[index] = setto
  648.                             elseif cmd == "GET" then
  649.                                 local setto = splt[5]
  650.                                 if containsKey(vars, setto) then
  651.                                     setValue(vars, setto, tabl[index])
  652.                                 else
  653.                                     return {"NONEXISTANT VAR", i}
  654.                                 end
  655.                             end
  656.                         end
  657.                     else
  658.                         return {"NONEXISTANT TABLE", i}
  659.                     end
  660.                 elseif key == "EVENT" then
  661.                     local cmd = splt[2]
  662.                     local varname = splt[3]
  663.                     if containsKey(vars, varname) then
  664.                         if cmd == "TYPE" then
  665.                             setValue(vars, varname, args[1])
  666.                         elseif cmd == "VAR" then
  667.                             local n = tonumber(splt[4])
  668.                             setValue(vars, varname, args[n-1])
  669.                         else
  670.                             return {"INVALID EVENT COMMAND", i}
  671.                         end
  672.                     else
  673.                         return {"NONEXISTANT VARIABLE", i}
  674.                     end
  675.                 elseif key == "MATH" then
  676.                    
  677.                     local name = splt[2]
  678.                    
  679.                     local mvls = {}
  680.                     local mms = {}
  681.                    
  682.                     if #splt > 4 then
  683.                         local num = true
  684.                         for i=3,#splt do
  685.                             if num then
  686.                                 local val1 = nil
  687.                                 local vtab1 = getVal(splt[i])
  688.                                 if vtab1[1] then val1 = vtab1[2] else return {vtab1[2], i} end
  689.                                
  690.                                 if val1 ~= nil then
  691.                                     if type(val1) == "number" then
  692.                                         mvls[#mvls + 1] = val1
  693.                                     else
  694.                                         return {"NON-NUMBER FOUND", i}
  695.                                     end
  696.                                 else
  697.                                     return {"NULL FOUND", i}
  698.                                 end
  699.                                 num = false
  700.                             else
  701.                                 mms[#mms + 1] = splt[i]
  702.                                 num = true
  703.                             end
  704.                         end
  705.                        
  706.                         local curv = mvls[1]
  707.                         local curs = 1
  708.                        
  709.                         for i=2,#mvls do
  710.                             curv = doMath(curv, mvls[i], mms[curs])
  711.                             curs = curs + 1
  712.                         end
  713.                        
  714.                         if containsKey(vars, name) then
  715.                             setValue(vars, name, curv)
  716.                         else
  717.                             return {"NONEXISTANT VAR", i}
  718.                         end
  719.                        
  720.                     else
  721.                         return {"INVALID MATH", i}
  722.                     end
  723.                 elseif key == "TERM" then
  724.                     local cmd = splt[2]
  725.                     if cmd == "PRINT" then
  726.                         local value = splt[3]
  727.                    
  728.                         if string.sub(value, 1, 1) == '"' and #splt > 3 then
  729.                             for j=4,#splt do
  730.                                 value = value.." "..splt[j]
  731.                             end
  732.                         end                
  733.                        
  734.                         local vtab = getVal(value)
  735.                         if vtab[1] then value = vtab[2] else return {vtab[2], i} end
  736.                        
  737.                         print(value)
  738.                     elseif cmd == "SIZE" then
  739.                         local x = splt[3]
  740.                         local y = splt[4]
  741.                        
  742.                         if containsKey(vars, x) and containsKey(vars, y) then
  743.                             local tx, ty = term.getSize()
  744.                             setValue(vars, x, tx)
  745.                             setValue(vars, y, ty)
  746.                         else
  747.                             return {"NONEXISTANT VAR(S)", i}
  748.                         end
  749.                     elseif cmd == "RESTORE" then
  750.                         term.restore()
  751.                     elseif cmd == "CLEARLN" then
  752.                         term.clearln()
  753.                     elseif cmd == "BLINK" then
  754.                         if blk then blk = false else blk = true end
  755.                         term.setCursorBlink(b)
  756.                     elseif cmd == "GETBLINK" then
  757.                         local value = splt[3]
  758.                         if containsKey(vars, value) then
  759.                             setValue(vars, balue, blk)
  760.                         else
  761.                             return {"NONEXISTANT VAR", i}
  762.                         end
  763.                     elseif cmd == "SCROLL" then
  764.                         local n = splt[3]
  765.                        
  766.                         local vtab = getVal(n)
  767.                         if vtab[1] then n = vtab[2] else return {vtab[2], i} end
  768.                        
  769.                         if type(n) == "number" then
  770.                             term.scroll(n)
  771.                         else
  772.                             return {"NON-NUMBER FOUND", i}
  773.                         end
  774.                     elseif cmd == "REDNET" then
  775.                         local rcmd = splt[3]
  776.                         if rcmd == "OPEN" then
  777.                             local side = splt[4]
  778.                            
  779.                             local vtab = getVal(side)
  780.                             if vtab[1] then side = vtab[2] else return {vtab[2], i} end
  781.                            
  782.                             rednet.open(side)
  783.                         elseif rcmd == "CLOSE" then
  784.                             local side = splt[4]
  785.                            
  786.                             local vtab = getVal(side)
  787.                             if vtab[1] then side = vtab[2] else return {vtab[2], i} end
  788.                            
  789.                             rednet.close(side)
  790.                         elseif rcmd == "ANC" then
  791.                             rednet.announce()
  792.                         elseif rcmd == "SEND" then
  793.                             local id = splt[4]
  794.                            
  795.                             local vtab = getVal(id)
  796.                             if vtab[1] then id = vtab[2] else return {vtab[2], i} end
  797.                            
  798.                             local message = splt[5]
  799.                            
  800.                             if string.sub(message, 1, 1) == '"' and #splt > 5 then
  801.                                 for j=6,#splt do
  802.                                     message =message.." "..splt[j]
  803.                                 end
  804.                             end
  805.                            
  806.                             local vtab = getVal(message)
  807.                             if vtab[1] then message = vtab[2] else return {vtab[2], i} end
  808.                            
  809.                             rednet.send(id, message)
  810.                         elseif rcmd == "CAST" then
  811.                             local message = splt[4]
  812.                            
  813.                             if string.sub(message, 1, 1) == '"' and #splt > 4 then
  814.                                 for j=5,#splt do
  815.                                     message =message.." "..splt[j]
  816.                                 end
  817.                             end
  818.                            
  819.                             local vtab = getVal(message)
  820.                             if vtab[1] then message = vtab[2] else return {vtab[2], i} end
  821.                            
  822.                             rednet.broadcast(message)
  823.                         elseif rcmd == "RECIEVE" then
  824.                             local timeout = splt[4]
  825.                            
  826.                             local vtab = getVal(timeout)
  827.                             if vtab[1] then timeout = vtab[2] else return {vtab[2], i} end
  828.                        
  829.                             local ntabl = splt[5]
  830.                             if containsKey(vars, tabl) then
  831.                                 local tabl = getValue(vars, ntabl)
  832.                                 if type(tabl) == "table" then
  833.                                     local sid, message, dist = rednet.recieve(timeout)
  834.                                     if sid == nil and message == nil and dist == nil then
  835.                                         setValue(vars, ntabl, {sid, message, dist})
  836.                                     end
  837.                                 else
  838.                                     return {"NON-TABLE FOUND", i}
  839.                                 end
  840.                             else
  841.                                 return {"NONEXISTANT TABLE", i}
  842.                             end
  843.                         end
  844.                     elseif cmd == "STOP" then
  845.                         on = false
  846.                     elseif cmd == "SLEEP" then
  847.                         local value = splt[3]
  848.                        
  849.                         local vtab = getVal(value)
  850.                         if vtab[1] then value = vtab[2] else return {vtab[2], i} end
  851.                        
  852.                         if type(value) == "number" then
  853.                             sleep(value)
  854.                         else
  855.                             return {"NONUMBER GIVEN", i}
  856.                         end
  857.                     elseif cmd == "TIMER" then
  858.                         local value = splt[3]
  859.                        
  860.                         local vtab = getVal(value)
  861.                         if vtab[1] then value = vtab[2] else return {vtab[2], i} end
  862.                        
  863.                         if type(value) == "number" then
  864.                             os.startTimer(value)
  865.                         else
  866.                             return {"NONUMBER GIVEN", i}
  867.                         end
  868.                     elseif cmd == "WRITE" then
  869.                         local value = splt[3]
  870.                    
  871.                         if string.sub(value, 1, 1) == '"' and #splt > 3 then
  872.                             for j=4,#splt do
  873.                                 value = value.." "..splt[j]
  874.                             end
  875.                         end                
  876.                        
  877.                         local vtab = getVal(value)
  878.                         if vtab[1] then value = vtab[2] else return {vtab[2], i} end
  879.                        
  880.                         term.write(value)
  881.                     elseif cmd == "SET" then
  882.                         local val1 = nil
  883.                         local vtab1 = getVal(splt[3])
  884.                         if vtab1[1] then val1 = vtab1[2] else return {vtab1[2], i} end
  885.                        
  886.                         local val2 = nil
  887.                         local vtab2 = getVal(splt[4])
  888.                         if vtab2[1] then val2 = vtab2[2] else return {vtab2[2], i} end
  889.                        
  890.                         if type(val1) == "number" and type(val2) == "number" then
  891.                             term.setCursorPos(val1, val2)
  892.                         else
  893.                             return ({"NON-NUMBER FOUND", i})
  894.                         end
  895.                     elseif cmd == "CLEAR" then
  896.                         term.clear()
  897.                     end
  898.                     -- comp: [type] [text] [loc]
  899.                     -- Button: [code] [states] [state]
  900.                 elseif key == "COMP" then
  901.                     local cmd = splt[2]
  902.                     local varname = splt[3]
  903.                     if containsKey(vars, varname) or cmd == "SET" then
  904.                         if cmd == "TEXT" then
  905.                             setValue(vars, varname, args[1][2])
  906.                         elseif cmd == "TYPE" then
  907.                             setValue(vars, varname, args[1][1])
  908.                         elseif cmd == "X" then
  909.                             setValue(vars, varname, args[1][3][1])
  910.                         elseif cmd == "Y" then
  911.                             setValue(vars, varname, args[1][3][2])
  912.                         elseif cmd == "WIDTH" or cmd == "W" then
  913.                             setValue(vars, varname, args[1][3][3])
  914.                         elseif cmd == "HEIGHT" or cmd == "H" then
  915.                             setValue(vars, varname, args[1][3][4])
  916.                         elseif cmd == "SET" then
  917.                             local cm = varname
  918.                             if containsKey(vars, splt[4]) then
  919.                                 local value = splt[4]
  920.                        
  921.                                 if string.sub(value, 1, 1) == '"' and #splt > 3 then
  922.                                     for j=4,#splt do
  923.                                         value = value.." "..splt[j]
  924.                                     end
  925.                                 end                
  926.                                
  927.                                 local vtab = getVal(value)
  928.                                 if vtab[1] then value = vtab[2] else return {vtab[2], i} end
  929.                                 if cmd == "TEXT" then
  930.                                     args[1][2] = value
  931.                                 elseif cmd == "TYPE" then
  932.                                     args[1][1] = value
  933.                                 elseif cmd == "X" then
  934.                                     args[1][3][1] = value
  935.                                 elseif cmd == "Y" then
  936.                                     args[1][3][2] = value
  937.                                 elseif cmd == "WIDTH" or cmd == "W" then
  938.                                     args[1][3][3] = value
  939.                                 elseif cmd == "HEIGHT" or cmd == "H" then
  940.                                     args[1][3][4] = value
  941.                                 else
  942.                                     return {"INVALID COMP CMD", i}
  943.                                 end
  944.                             else
  945.                                 return {"NONEXISTANT VAR", i}
  946.                             end
  947.                         else
  948.                             return {"INVALID COMP CMD", i}
  949.                         end
  950.                     else
  951.                         return {"NONEXISTANT VAR", i}
  952.                     end
  953.                 elseif key == "SETFUNC" then
  954.                     local name = splt[2]
  955.                     local cname = splt[3]
  956.                     if containsKey(ds, cname) then
  957.                         local code = getValue(ds, cname)
  958.                         if containsKey(funcs, name) then
  959.                             setValue(funcs, name, code)
  960.                         else
  961.                             putValue(funcs, name, code)
  962.                         end
  963.                     else
  964.                         return {"NONEXISTANT CODE", i}
  965.                     end
  966.                 elseif key == "STRING" then
  967.                     local cmd = splt[2]
  968.                     if cmd == "CONCAT" then
  969.                         local result = splt[3]
  970.                         local vals = {}
  971.                         for i=4,#splt do
  972.                             vals[#vals + 1] = splt[i]
  973.                         end
  974.                        
  975.                         local str = ""
  976.                         for i=1,#vals do
  977.                             local value = vals[i]
  978.                             local vtab = getVal(value)
  979.                             if vtab[1] then value = vtab[2] else return {vtab[2], i} end
  980.                            
  981.                             if type(value) == "string" then
  982.                                 if i == 1 then
  983.                                     str = value
  984.                                 else
  985.                                     str = str..value
  986.                                 end
  987.                             end
  988.                         end
  989.                        
  990.                         if containsKey(vars, result) then
  991.                             setValue(vars, result, str)
  992.                         else
  993.                             putValue(vars, result, str)
  994.                         end
  995.                     elseif cmd == "CUT" then
  996.                         local result = splt[3]
  997.                         local from = splt[4]
  998.                         local to = splt[5]
  999.                        
  1000.                         local vtab1 = getVal(from)
  1001.                         if vtab1[1] then from = vtab1[2] else return {vtab1[2], i} end
  1002.                         local vtab2 = getVal(to)
  1003.                         if vtab2[1] then to = vtab2[2] else return {vtab2[2], i} end
  1004.                        
  1005.                         local value = splt[6]
  1006.                        
  1007.                         if string.sub(value, 1, 1) == '"' and #splt > 4 then
  1008.                             for j=5,#splt do
  1009.                                 value = value.." "..splt[j]
  1010.                             end
  1011.                         end
  1012.                        
  1013.                         local vtab = getVal(value)
  1014.                         if vtab[1] then value = vtab[2] else return {vtab[2], i} end
  1015.                        
  1016.                         local res = string.sub(value, from, to)
  1017.                         if containsKey(vars, result) then
  1018.                             setValue(vars, result, res)
  1019.                         else
  1020.                             return {"INVALID VAR", i}
  1021.                         end
  1022.                     elseif cmd == "RPL" then
  1023.                         local result = splt[3]
  1024.                         local from = splt[4]
  1025.                         local to = splt[5]
  1026.                        
  1027.                         local vtab1 = getVal(from)
  1028.                         if vtab1[1] then from = vtab1[2] else return {vtab1[2], i} end
  1029.                         local vtab2 = getVal(to)
  1030.                         if vtab2[1] then to = vtab2[2] else return {vtab2[2], i} end
  1031.                        
  1032.                         local value = splt[6]
  1033.                        
  1034.                         if string.sub(value, 1, 1) == '"' and #splt > 6 then
  1035.                             for j=7,#splt do
  1036.                                 value = value.." "..splt[j]
  1037.                             end
  1038.                         end
  1039.                        
  1040.                         local vtab = getVal(value)
  1041.                         if vtab[1] then value = vtab[2] else return {vtab[2], i} end
  1042.                        
  1043.                         local res = string.gsub(value, from, to)
  1044.                         if containsKey(vars, result) then
  1045.                             setValue(vars, result, res)
  1046.                         else
  1047.                             return {"INVALID VAR", i}
  1048.                         end
  1049.                     elseif cmd == "SPLIT" then
  1050.                         local varname = splt[3]
  1051.                         local spltat = splt[4]
  1052.                        
  1053.                         local vtab1 = getVal(spltat)
  1054.                         if vtab1[1] then from = vtab1[2] else return {vtab1[2], i} end
  1055.                        
  1056.                         local value = splt[5]
  1057.                        
  1058.                         if string.sub(value, 1, 1) == '"' and #splt > 6 then
  1059.                             for j=7,#splt do
  1060.                                 value = value.." "..splt[j]
  1061.                             end
  1062.                         end
  1063.                        
  1064.                         local vtab = getVal(value)
  1065.                         if vtab[1] then value = vtab[2] else return {vtab[2], i} end
  1066.                        
  1067.                         if containsKey(vars, varname) then
  1068.                             setValue(vars, varname, split(value, spltat))
  1069.                         else
  1070.                             putValue(vars, varname, split(value, spltat))
  1071.                         end
  1072.                     elseif cmd == "ISPLIT" then
  1073.                         local result = splt[3]
  1074.                         local spltat = splt[4]
  1075.                         local index = splt[5]
  1076.                        
  1077.                         local vtab1 = getVal(spltat)
  1078.                         if vtab1[1] then from = vtab1[2] else return {vtab1[2], i} end
  1079.                         local vtab2 = getVal(index)
  1080.                         if vtab2[1] then from = vtab2[2] else return {vtab2[2], i} end
  1081.                        
  1082.                         local value = splt[6]
  1083.                        
  1084.                         if string.sub(value, 1, 1) == '"' and #splt > 6 then
  1085.                             for j=7,#splt do
  1086.                                 value = value.." "..splt[j]
  1087.                             end
  1088.                         end
  1089.                        
  1090.                         local vtab = getVal(value)
  1091.                         if vtab[1] then value = vtab[2] else return {vtab[2], i} end
  1092.                        
  1093.                         local spl = split(value, spltat)
  1094.                         local res = spl[index]
  1095.                         if containsKey(vars, result) then
  1096.                             setValue(vars, result, res)
  1097.                         else
  1098.                             return {"INVALID VAR", i}
  1099.                         end
  1100.                     else
  1101.                         return {"INVALID STRING CMD", i}
  1102.                     end
  1103.                
  1104.                 elseif key == "IO" then
  1105.                     local cmd = splt[2]
  1106.                     local fname = splt[3]
  1107.                     if cmd == "CREATE" then
  1108.                         local f = fs.open(fname, "a")
  1109.                         f.close()
  1110.                     elseif cmd == "DELETE" then
  1111.                         fs.delete(fname)
  1112.                     elseif cmd == "OPEN" then
  1113.                         local styp = splt[4]
  1114.                         local typ = "a"
  1115.                         if styp == "write" then
  1116.                             typ = "a"
  1117.                         elseif styp == "read" then
  1118.                             typ = "r"
  1119.                         else
  1120.                             return {"INVALID FILE TYPE", i}
  1121.                         end
  1122.                        
  1123.                         local fn = splt[5]
  1124.                        
  1125.                         if containsKey(curf, fn) then
  1126.                             return {"FILE ALREADY EXISTS", i}
  1127.                         else
  1128.                             curf[#curf + 1] = {fn, fs.open(fname, typ)}
  1129.                         end
  1130.                     elseif cmd == "CLOSE" then
  1131.                         if containsKey(curf, fname) then
  1132.                             local f = getValue(curf, fname)
  1133.                             f.close()
  1134.                             delValue(curf, fname)
  1135.                         else
  1136.                             return {"NONEXISTANT FILE", i}
  1137.                         end
  1138.                     elseif cmd == "WRITE" then
  1139.                         if containsKey(curf, fname) then
  1140.                             local f = getValue(curf, fname)
  1141.                             local value = splt[4]
  1142.                            
  1143.                             if string.sub(value, 1, 1) == '"' and #splt > 4 then
  1144.                                 for j=5,#splt do
  1145.                                     value = value.." "..splt[j]
  1146.                                 end
  1147.                             end
  1148.                            
  1149.                             local vtab = getVal(value)
  1150.                             if vtab[1] then value = vtab[2] else return {vtab[2], i} end
  1151.                            
  1152.                             f.writeLine(value)
  1153.                         else
  1154.                             return {"NONEXISTANT FILE", i}
  1155.                         end
  1156.                     elseif cmd == "READ" then
  1157.                         if containsKey(curf, fname) then
  1158.                             local f = getValue(curf, fname)
  1159.                             local var1 = splt[4]
  1160.                             if containsKey(vars, var1) then
  1161.                                 local ln = f.readLine()
  1162.                                 if ln ~= nil then
  1163.                                     setValue(vars, var1, ln)
  1164.                                 else
  1165.                                     setValue(vars, var1, false)
  1166.                                 end
  1167.                             else
  1168.                                 return {"NONEXISTANT VAR", i}
  1169.                             end
  1170.                         else
  1171.                             return {"NONEXISTANT FILE", i}
  1172.                         end
  1173.                     elseif cmd == "READF" then
  1174.                         if containsKey(furc, fname) then
  1175.                             local f = getValue(curf, fname)
  1176.                             local var1 = splt[4]
  1177.                             if containsKey(vars, var1) then
  1178.                                 local tabl = {}
  1179.                                 local ln = f.readLine()
  1180.                                 while ln ~= nil do
  1181.                                     tabl[#tabl + 1] = ln
  1182.                                     ln = f.readLine()
  1183.                                 end
  1184.                                 setValue(vars, var1, tabl)
  1185.                             else
  1186.                                 return {"NONEXISTANT VAR", i}
  1187.                             end
  1188.                         end
  1189.                     else
  1190.                         return {"INVALID IO COMMAND", i}
  1191.                     end
  1192.                    
  1193.                 elseif key == "*" then
  1194.                     kon = true
  1195.                     if #splt >= 2 then
  1196.                         cdn = splt[2]
  1197.                         cd = {}
  1198.                     else
  1199.                         return {"NO CODE NAME", i}
  1200.                     end
  1201.                 else
  1202.                     return {"INVALID COMMAND", i}
  1203.                 end
  1204.             else
  1205.                 if splt[1] == "*" or part == "*" then
  1206.                     kon = false
  1207.                     ds[#ds + 1] = {cdn, cd}
  1208.                     cd = {}
  1209.                     cdn = nil
  1210.                 else
  1211.                     cd[#cd + 1] = part
  1212.                 end
  1213.             end
  1214.         end
  1215.     end
  1216.     return nil
  1217. end
  1218.  
  1219. function runC(code, index, args)
  1220.     if args == nil then args = {"NONE"} end
  1221.     local er = runCode(code, args)
  1222.     if er ~= nil then
  1223.         setLog(er[1].."@"..index..";"..er[2])
  1224.         return false
  1225.     end
  1226.     return true
  1227. end
  1228.  
  1229. local function setPixel(x, y, str)
  1230.     local oldx, oldy = term.getCursorPos()
  1231.     term.setCursorPos(x, y)
  1232.     term.write(str)
  1233.     term.setCursorPos(oldx, oldy)
  1234. end
  1235.  
  1236. local function interact(x, y)
  1237.    
  1238.     for i=1,#interactions do
  1239.         local comp = interactions[i]
  1240.         if #comp[3] >= 4 then
  1241.             if comp[3][1] <= x and comp[3][2] <= y and comp[3][3]+comp[3][1] >= x and comp[3][4]+comp[3][2] >= y then
  1242.                 local type = comp[1]
  1243.                 if comp == "button" then
  1244.                     local code = comp[4]
  1245.                     runC(code, i, {comp})
  1246.                 elseif comp == "input" then
  1247.                     selected = comp
  1248.                 end
  1249.             end
  1250.         end
  1251.     end
  1252.     return false
  1253. end
  1254.  
  1255. local function inputChar(ch)
  1256.     if selected ~= nil then
  1257.         if selected[1] == "input" then
  1258.             selected[2] = selected[2]..ch
  1259.             if containsKey(vars, selected[4]) then
  1260.                 setValue(vars, selected[4], selected[2])
  1261.             else
  1262.                 putValue(vars, selected[4], selected[2])
  1263.             end
  1264.         end
  1265.     end
  1266. end
  1267.  
  1268. -- comp: [type] [text] [loc]
  1269. -- Button: [code] [states] [state]
  1270. -- Input: [varname] [states] [state] [cursor]
  1271.  
  1272. function loadMenu(dir)
  1273.     if fs.exists(dir) then
  1274.         local file = fs.open(dir, "r")
  1275.         local line = file.readLine()
  1276.         local btyp = ""
  1277.         local name = ""
  1278.         local cur = {}
  1279.         local ison = false
  1280.         local cmt = true
  1281.         while line ~= nil do
  1282.             line = string.gsub(line, "\t", "")
  1283.             if ison and cmt and string.gsub(line, " ", "") ~= "" and line ~= "::" then
  1284.                 local curl = ""
  1285.                 local curn = 1
  1286.                
  1287.                 while string.gsub(curl, " ", "") == "" do
  1288.                     curl = string.sub(line, 1, curn)
  1289.                     curn = curn + 1
  1290.                 end
  1291.                
  1292.                 local l = string.sub(line, curn-1, -1)
  1293.                
  1294.                 if btyp == "" then
  1295.                     if string.sub(l, 1, 4) == "func" then
  1296.                         local splt = split(l, ":~:")
  1297.                         name = splt[2]
  1298.                     else
  1299.                         btyp = string.lower(l)
  1300.                     end
  1301.                 else
  1302.                     if btyp == "comp" then
  1303.                         local splt = split(l, ":~:")
  1304.                         local type = splt[1]
  1305.                        
  1306.                         if type == "type" then
  1307.                             cur[1] = splt[2]
  1308.                         elseif type == "text" then
  1309.                             cur[2] = splt[2]
  1310.                         elseif type == "loc" then
  1311.                             cur[3] = {}
  1312.                             local c = cur[3]
  1313.                             for i=2,#splt do
  1314.                                 c[#c + 1] = tonumber(splt[i])
  1315.                             end
  1316.                             cur[3] = c
  1317.                         elseif type == "code" then
  1318.                             cur[4] = getValue(funcs, splt[2])
  1319.                         elseif type == "states" then
  1320.                             cur[5] = {}
  1321.                             local c = cur[5]
  1322.                             for i=2,#splt do
  1323.                                 c[#c + 1] = splt[i]
  1324.                             end
  1325.                             cur[5] = c
  1326.                         elseif type == "state" then
  1327.                             cur[6] = tonumber(splt[2])
  1328.                         elseif type == "cursor" then
  1329.                             cur[7] = tonumber(splt[2])
  1330.                         elseif type == "varname" then
  1331.                             cur[4] = splt[2]
  1332.                         end
  1333.                     elseif btyp == "func" then
  1334.                         cur[#cur + 1] = l
  1335.                     elseif btyp == "startup" then
  1336.                         cur[#cur + 1] = l
  1337.                     elseif btyp == "update" then
  1338.                         cur[#cur + 1] = l
  1339.                     elseif btyp == "event" then
  1340.                         cur[#cur + 1] = l
  1341.                     elseif btype == "end" then
  1342.                         cur[#cur + 1] = l
  1343.                     end
  1344.                 end
  1345.             end
  1346.             if line == "#:" then
  1347.                 cmt = true
  1348.             end
  1349.             if line == ":#" then
  1350.                 cmt = false
  1351.             end
  1352.             if line == "::" then
  1353.                 if ison then
  1354.                     print("CLOSED:"..btyp)
  1355.                     ison = false
  1356.                     if btyp == "comp" then
  1357.                         interactions[#interactions + 1] = cur
  1358.                     elseif btyp == "func" then
  1359.                         if containsKey(funcs, name) then
  1360.                             setValue(funcs, name, cur)
  1361.                         else
  1362.                             putValue(funcs, name, cur)
  1363.                         end
  1364.                     elseif btyp == "startup" then
  1365.                         print("LOADED STARTUP")
  1366.                         startup = cur
  1367.                     elseif btyp == "update" then
  1368.                         updte = cur
  1369.                     elseif btyp == "event" then
  1370.                         oevent = cur
  1371.                     elseif btyp == "end" then
  1372.                         ecode = cur
  1373.                     end
  1374.                     btyp = ""
  1375.                     name = ""
  1376.                     cur = {}
  1377.                 else ison = true print("OPENED") end
  1378.             end
  1379.             print(line)
  1380.             line = file.readLine()
  1381.         end
  1382.         file.close()
  1383.         return true
  1384.     end
  1385.     return false
  1386. end
  1387.  
  1388. local function drawComponent(comp)
  1389.     local type = comp[1]
  1390.     local text = comp[2]
  1391.     local loc = comp[3]
  1392.     local x = loc[1]
  1393.     local y = loc[2]
  1394.     if type == "button" then
  1395.         local w = loc[3]
  1396.         local h = loc[4]-1
  1397.         local states = comp[5]
  1398.         local state = states[comp[6]]
  1399.         local s = {}
  1400.         for i=1,string.len(state) do
  1401.             s[#s + 1] = string.sub(state, i, i)
  1402.         end
  1403.         setPixel(x, y, s[1])
  1404.         setPixel(x+w, y, s[2])
  1405.         setPixel(x, y+h, s[3])
  1406.         setPixel(x+w, y+h, s[4])
  1407.         for i=x+1, x+w-1, 1 do
  1408.             setPixel(i, y, s[5])
  1409.             setPixel(i, y+h, s[7])
  1410.         end
  1411.         for i=y+1, x+h-1, 1 do
  1412.             setPixel(x, i, s[6])
  1413.             setPixel(x+w, i, s[8])
  1414.         end
  1415.         local ry = y+(h/2)
  1416.         local rx = x+(w/2)-(string.len(text)/2)
  1417.         setPixel(rx, ry, text)
  1418.     elseif type == "input" then
  1419.         local states = comp[5]
  1420.         local s = states[comp[6]]
  1421.         local cur = comp[7]
  1422.         setPixel(x, y, s[1])
  1423.         setPixel(x+w, y, s[2])
  1424.         setPixel(x+1, y, s[3])
  1425.         local rtext = string.sub(text, cur, -1)
  1426.         if (w-3)+cur < string.len(rtext) then
  1427.             rtext = string.sub(rtext, cur, cur+(w-3))
  1428.         end
  1429.         setPixel(x+2, y, rtext)
  1430.     elseif type == "label" then
  1431.         setPixel(x, y, text)
  1432.     end
  1433. end
  1434.  
  1435. local stuff = {...}
  1436. print("LOOKING AT STUFF")
  1437. if #stuff == 1 then
  1438.     print("LOADING MENU: "..stuff[1])
  1439.     if loadMenu(stuff[1]) then
  1440.         print("OK")
  1441.         on = runC(startup, 0, nil)
  1442.         local timer = os.startTimer(1)
  1443.        
  1444.         local interval = 0.5
  1445.         local n = 0
  1446.         while on do
  1447.             if on then
  1448.                 local event, p1, p2, p3 = os.pullEvent()
  1449.                     local kon = true
  1450.                     if event == "timer" and p1 == timer then
  1451.                         if on then
  1452.                             timer = os.startTimer(interval)
  1453.                             --print(n)
  1454.                             if #interactions > 0 then
  1455.                                 for i=1,#interactions do
  1456.                                     local comp = interactions[i]
  1457.                                     drawComponent(comp)
  1458.                                 end
  1459.                             end
  1460.                             if on then
  1461.                                 kon = runC(updte, 0, nil)
  1462.                             end
  1463.                         end
  1464.                     elseif event == "char" then
  1465.                         inputChar(p1)
  1466.                         if on then kon = runC(oevent, 0, {"char", p1}) end
  1467.                     elseif event ~= nil and event ~= "" then
  1468.                         if on then
  1469.                             if p2 == nil then
  1470.                                 kon = runC(oevent, 0, {event, p1})
  1471.                             elseif p3 == nil then
  1472.                                 kon = runC(oevent, 0, {event, p1, p2})
  1473.                             elseif p3 ~= nil then
  1474.                                 kon = runC(oevent, 0, {event, p1, p2, p3})
  1475.                             end
  1476.                         end
  1477.                     end
  1478.                     if on then
  1479.                         on = kon
  1480.                     end
  1481.                 n = n + 1
  1482.             else
  1483.                 break
  1484.             end
  1485.             --sleep(0)
  1486.         end
  1487.         if not runC(ecode, 0, nil) then
  1488.             term.clear()
  1489.             term.setCursorPos(1,1)
  1490.         end
  1491.     end
  1492. else
  1493.     print("INVALID INPUT")
  1494. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement