Advertisement
Guest User

Untitled

a guest
Dec 23rd, 2014
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. m=component.proxy(component.list("modem")())
  2. m.open(2412)
  3. computer.beep(2000)
  4. function print(...)
  5. local args=table.pack(...)
  6. pcall(function() m.broadcast(2412, table.unpack(args)) end)
  7. end
  8. function read(pref,repchar)
  9. if pref ~= nil then print(pref) end
  10. repeat
  11. evt,_,_,_,_,cmd=computer.pullSignal()
  12. until evt == "modem_message"
  13. computer.beep(200)
  14. return cmd
  15. end
  16. local function splitonspace(str)
  17. local t = {}
  18. for w in str:gmatch("%S+") do
  19. table.insert(t,w)
  20. end
  21. computer.beep()
  22. return t
  23. end
  24. print("skex BIOS v0.1")
  25. print((math.floor(computer.totalMemory()/1024)).."k total, "..tostring(math.floor(computer.freeMemory()/1024)).."k free, "..tostring(math.floor((computer.totalMemory()-computer.freeMemory())/1024)).."k used")
  26. function error(...)
  27. print(...)
  28. end
  29.  
  30. local cmds = {"q - quit skex",
  31. "l <start> <end> - writes the lines from <start> (default 1) to <end> (default #b) to stdout",
  32. "lc - writes the current line to stdout",
  33. "s [line] - seeks to a line",
  34. "so - writes the number of the current line to stdout",
  35. "i - inserts/appends lines, a line with only . to exit this mode",
  36. "e - executes the code in the buffer",
  37. "d - deletes the current line",
  38. "r - replaces the current line",
  39. "? / h - prints this help message"}
  40.  
  41. local run = true
  42. local b = {}
  43. local l = 1
  44.  
  45. while run do
  46. local cmdt = splitonspace(read())
  47. if cmdt[1] == "q" then
  48. run = false
  49. elseif cmdt[1] == "o" then
  50. -- local f = syscall.execute("fs_open",cmdt[2],"r")
  51. -- a="" repeat c=f.read() if c==nil then c="" end a=a..c until c=="" f.close() for L in a:gmatch("[^\r\n]+") do table.insert(b,l,L) l=l+1 end
  52. elseif cmdt[1] == "l" then
  53. startn,endn = cmdt[2],cmdt[3]
  54. if cmdt[2] == nil then
  55. startn=1
  56. end
  57. if cmdt[3] == nil then
  58. endn=#b
  59. end
  60. print("Line "..startn.." to "..endn..":")
  61. for i = tonumber(startn),tonumber(endn) do
  62. print(b[i])
  63. end
  64. elseif cmdt[1] == "lc" then
  65. print(b[l])
  66. elseif cmdt[1] == "so" then
  67. print("Current line: "..l)
  68. elseif cmdt[1] == "s" then
  69. l = tonumber(cmdt[2])
  70. elseif cmdt[1] == "i" then
  71. c=read("insert")
  72. repeat
  73. table.insert(b,l,c)
  74. l=l+1
  75. c=read()
  76. until c=="."
  77. elseif cmdt[1] == "w" then
  78. -- f=syscall.execute("fs_open",cmdt[2],"w")
  79. -- print(f)
  80. -- for k,v in pairs(b) do
  81. -- f.write(v.."\n")
  82. -- end
  83. -- f.close()
  84. elseif cmdt[1] == "e" then
  85. cd=""
  86. for k,v in pairs(b) do
  87. cd=cd..v.."\n"
  88. end
  89. print(pcall(load(cd)))
  90. elseif cmdt[1] == "d" then
  91. print(table.remove(b,l))
  92. elseif cmdt[1] == "r" then
  93. b[l] = read("replace")
  94. elseif cmdt[1] == "?" or cmdt[1]:sub(1,1) == "h" then
  95. print("Commands:")
  96. print("Arguments surrounded by []s are mandatory, arguments surrounded by <> are optional.")
  97. for k,v in ipairs(cmds) do
  98. print(v)
  99. end
  100. end
  101. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement