Advertisement
TheReturningVoid

Untitled

Jan 20th, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.07 KB | None | 0 0
  1. m=component.proxy(component.list("modem")())
  2. m.open(2412)
  3. computer.beep(2000)
  4. local eventStack = {}
  5. local listeners = {}
  6. event = {}
  7. function event.listen(evtype,callback)
  8. if listeners[evtype] ~= nil then
  9. table.insert(listeners[evtype],callback)
  10. return #listeners
  11. else
  12. listeners[evtype] = {callback}
  13. return 1
  14. end
  15. end
  16. function event.ignore(evtype,id)
  17. table.remove(listeners[evtype],id)
  18. end
  19. function event.pull(filter)
  20. if not filter then return table.remove(eventStack,1)
  21. else
  22. for _,v in pairs(eventStack) do
  23. if v == filter then
  24. return v
  25. end
  26. end
  27. repeat
  28. t=table.pack(computer.pullSignal())
  29. evtype = table.remove(t,1)
  30. if listeners[evtype] ~= nil then
  31. for k,v in pairs(listeners[evtype]) do
  32. local evt,rasin = pcall(v,evtype,table.unpack(t))
  33. if not evt then
  34. print("stdout_write","ELF: "..tostring(evtype)..":"..tostring(k)..":"..rasin)
  35. end
  36. end
  37. end
  38. until evtype == filter
  39. return evtype, table.unpack(t)
  40. end
  41. end
  42. function print(...)
  43. local args=table.pack(...)
  44. pcall(function() m.broadcast(2412, table.unpack(args)) end)
  45. end
  46. local rS = {}
  47. event.listen("modem_message",function(_,_,_,_,_,cmd)
  48. table.insert(rS,cmd)
  49. computer.beep()
  50. computer.pushSignal("read_return")
  51. end)
  52. function read(pref,repchar)
  53. local a,_ = table.remove(rS,1)
  54. if a == nil then
  55. event.pull("read_return")
  56. return table.remove(rS,1)
  57. else return a end
  58. end
  59. local function splitonspace(str)
  60. local t = {}
  61. for w in str:gmatch("%S+") do
  62. table.insert(t,w)
  63. end
  64. computer.beep()
  65. return t
  66. end
  67. function sleep(n)
  68. local t0 = computer.uptime()
  69. while computer.uptime() - t0 <= n do computer.pushSignal("wait") computer.pullSignal() end
  70. end
  71. print("skex BIOS v0.1.1")
  72. 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")
  73. function error(...)
  74. print(...)
  75. end
  76.  
  77. local cmds = {"q - quit skex",
  78. "l <start> <end> - writes the lines from <start> (default 1) to <end> (default #b) to stdout",
  79. "lc - writes the current line to stdout",
  80. "s [line] - seeks to a line",
  81. "so - writes the number of the current line to stdout",
  82. "i - inserts/appends lines, a line with only . to exit this mode",
  83. "e - executes the code in the buffer",
  84. "ei - interactive lua mode, works like the OpenOS lua program",
  85. "d - deletes the current line",
  86. "cb - clears the whole buffer",
  87. "r - replaces the current line",
  88. "fb - re-flashes the BIOS from input, . to end and flash the EEPROM",
  89. "? / h - prints this help message"}
  90.  
  91. local run = true
  92. local b = {}
  93. local l = 1
  94.  
  95. while run do
  96. local cmdt = splitonspace(read())
  97. if cmdt[1] == "q" then
  98. run = false
  99. elseif cmdt[1] == "l" then
  100. startn,endn = cmdt[2],cmdt[3]
  101. if cmdt[2] == nil then
  102. startn=1
  103. end
  104. if cmdt[3] == nil then
  105. endn=#b
  106. end
  107. print("Line "..startn.." to "..endn..":")
  108. for i = tonumber(startn),tonumber(endn) do
  109. print(b[i])
  110. end
  111. elseif cmdt[1] == "lc" then
  112. print(b[l])
  113. elseif cmdt[1] == "so" then
  114. print("Current line: "..l)
  115. elseif cmdt[1] == "s" then
  116. l = tonumber(cmdt[2])
  117. elseif cmdt[1] == "i" then
  118. c=read()
  119. repeat
  120. table.insert(b,l,c)
  121. l=l+1
  122. c=read()
  123. until c=="."
  124. elseif cmdt[1] == "e" then
  125. cd=""
  126. for k,v in pairs(b) do
  127. cd=cd..v.."\n"
  128. end
  129. print(pcall(load(cd)))
  130. elseif cmdt[1] == "ei" then
  131. c=read()
  132. repeat
  133. print(pcall(load(c)))
  134. c=read()
  135. until c=="."
  136. elseif cmdt[1] == "d" then
  137. print(table.remove(b,l))
  138. elseif cmdt[1] == "r" then
  139. b[l] = read()
  140. elseif cmdt[1] == "cb" then
  141. b = {}
  142. elseif cmdt[1] == "fb" then
  143. c=read()
  144. nb = ""
  145. repeat
  146. nb = nb .. c .. "\n"
  147. c = read()
  148. until c=="."
  149. eeprom = component.proxy(component.list("eeprom")())
  150. eeprom.set(nb)
  151. computer.shutdown(true)
  152. elseif cmdt[1] == "?" or cmdt[1]:sub(1,1) == "h" then
  153. print("Commands:")
  154. print("Arguments surrounded by []s are mandatory, arguments surrounded by <> are optional.")
  155. for k,v in ipairs(cmds) do
  156. print(v)
  157. end
  158. end
  159. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement