Sirshark10

WORK

Jun 9th, 2016
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.97 KB | None | 0 0
  1.  
  2. local nativegetfenv = getfenv
  3. getfenv = nativegetfenv
  4. if _VERSION == "Lua 5.1" then
  5. -- If we're on Lua 5.1, install parts of the Lua 5.2/5.3 API so that programs can be written against it
  6. local nativeload = load
  7. local nativeloadstring = loadstring
  8. local nativesetfenv = setfenv
  9. function load( x, name, mode, env )
  10. if mode ~= nil and mode ~= "t" then
  11. error( "Binary chunk loading prohibited", 2 )
  12. end
  13. local ok, p1, p2 = pcall( function()
  14. if type(x) == "string" then
  15. local result, err = nativeloadstring( x, name )
  16. if result then
  17. if env then
  18. env._ENV = env
  19. nativesetfenv( result, env )
  20. end
  21. return result
  22. else
  23. return nil, err
  24. end
  25. else
  26. local result, err = nativeload( x, name )
  27. if result then
  28. if env then
  29. env._ENV = env
  30. nativesetfenv( result, env )
  31. end
  32. return result
  33. else
  34. return nil, err
  35. end
  36. end
  37. end )
  38. if ok then
  39. return p1, p2
  40. else
  41. error( p1, 2 )
  42. end
  43. end
  44. table.unpack = unpack
  45. table.pack = function( ... ) return { n = select( "#", ... ), ... } end
  46.  
  47. -- Install the bit32 api
  48. local nativebit = bit
  49. bit32 = {}
  50. bit32.arshift = nativebit.brshift
  51. bit32.band = nativebit.band
  52. bit32.bnot = nativebit.bnot
  53. bit32.bor = nativebit.bor
  54. bit32.btest = function( a, b ) return nativebit.band(a,b) ~= 0 end
  55. bit32.bxor = nativebit.bxor
  56. bit32.lshift = nativebit.blshift
  57. bit32.rshift = nativebit.blogic_rshift
  58.  
  59. if _CC_DISABLE_LUA51_FEATURES then
  60. -- Remove the Lua 5.1 features that will be removed when we update to Lua 5.2, for compatibility testing.
  61. -- See "disable_lua51_functions" in ComputerCraft.cfg
  62. a = getfenv
  63. end
  64. end
  65.  
  66. if _VERSION == "Lua 5.3" then
  67. -- If we're on Lua 5.3, install the bit32 api from Lua 5.2
  68. -- (Loaded from a string so this file will still parse on <5.3 lua)
  69. load( [[
  70. bit32 = {}
  71.  
  72. function bit32.arshift( n, bits )
  73. if type(n) ~= "number" or type(bits) ~= "number" then
  74. error( "Expected number, number", 2 )
  75. end
  76. return n >> bits
  77. end
  78.  
  79. function bit32.band( m, n )
  80. if type(m) ~= "number" or type(n) ~= "number" then
  81. error( "Expected number, number", 2 )
  82. end
  83. return m & n
  84. end
  85.  
  86. function bit32.bnot( n )
  87. if type(n) ~= "number" then
  88. error( "Expected number", 2 )
  89. end
  90. return ~n
  91. end
  92.  
  93. function bit32.bor( m, n )
  94. if type(m) ~= "number" or type(n) ~= "number" then
  95. error( "Expected number, number", 2 )
  96. end
  97. return m | n
  98. end
  99.  
  100. function bit32.btest( m, n )
  101. if type(m) ~= "number" or type(n) ~= "number" then
  102. error( "Expected number, number", 2 )
  103. end
  104. return (m & n) ~= 0
  105. end
  106.  
  107. function bit32.bxor( m, n )
  108. if type(m) ~= "number" or type(n) ~= "number" then
  109. error( "Expected number, number", 2 )
  110. end
  111. return m ~ n
  112. end
  113.  
  114. function bit32.lshift( n, bits )
  115. if type(n) ~= "number" or type(bits) ~= "number" then
  116. error( "Expected number, number", 2 )
  117. end
  118. return n << bits
  119. end
  120.  
  121. function bit32.rshift( n, bits )
  122. if type(n) ~= "number" or type(bits) ~= "number" then
  123. error( "Expected number, number", 2 )
  124. end
  125. return n >> bits
  126. end
  127. ]] )()
  128. end
  129.  
  130. if string.find( _HOST, "ComputerCraft" ) == 1 then
  131. -- Prevent access to metatables or environments of strings, as these are global between all computers
  132. local nativegetmetatable = getmetatable
  133. local nativeerror = error
  134. local nativetype = type
  135. local string_metatable = nativegetmetatable("")
  136. function getmetatable( t )
  137. local mt = nativegetmetatable( t )
  138. if mt == string_metatable then
  139. nativeerror( "Attempt to access string metatable", 2 )
  140. else
  141. return mt
  142. end
  143. end
  144. if _VERSION == "Lua 5.1" and not _CC_DISABLE_LUA51_FEATURES then
  145. local string_env = nativegetfenv(("").gsub)
  146. function getfenv( env )
  147. if env == nil then
  148. env = 2
  149. elseif nativetype( env ) == "number" and env > 0 then
  150. env = env + 1
  151. end
  152. local fenv = nativegetfenv(env)
  153. if fenv == string_env then
  154. --nativeerror( "Attempt to access string metatable", 2 )
  155. return nativegetfenv( 0 )
  156. else
  157. return fenv
  158. end
  159. end
  160. end
  161. end
  162.  
  163. -- Install lua parts of the os api
  164. function os.version()
  165. return "FUCK YOU CC"
  166. end
  167.  
  168. function os.pullEventRaw( sFilter )
  169. return coroutine.yield( sFilter )
  170. end
  171.  
  172. function os.pullEvent( sFilter )
  173. local eventData = { os.pullEventRaw( sFilter ) }
  174. if eventData[1] == "terminate" then
  175. error( "Terminated", 0 )
  176. end
  177. return table.unpack( eventData )
  178. end
  179.  
  180. -- Install globals
  181. function sleep( nTime )
  182. local timer = os.startTimer( nTime or 0 )
  183. repeat
  184. local sEvent, param = os.pullEvent( "timer" )
  185. until param == timer
  186. end
  187.  
  188. function write( sText )
  189. local w,h = term.getSize()
  190. local x,y = term.getCursorPos()
  191.  
  192. local nLinesPrinted = 0
  193. local function newLine()
  194. if y + 1 <= h then
  195. term.setCursorPos(1, y + 1)
  196. else
  197. term.setCursorPos(1, h)
  198. term.scroll(1)
  199. end
  200. x, y = term.getCursorPos()
  201. nLinesPrinted = nLinesPrinted + 1
  202. end
  203.  
  204. -- Print the line with proper word wrapping
  205. while string.len(sText) > 0 do
  206. local whitespace = string.match( sText, "^[ \t]+" )
  207. if whitespace then
  208. -- Print whitespace
  209. term.write( whitespace )
  210. x,y = term.getCursorPos()
  211. sText = string.sub( sText, string.len(whitespace) + 1 )
  212. end
  213.  
  214. local newline = string.match( sText, "^\n" )
  215. if newline then
  216. -- Print newlines
  217. newLine()
  218. sText = string.sub( sText, 2 )
  219. end
  220.  
  221. local text = string.match( sText, "^[^ \t\n]+" )
  222. if text then
  223. sText = string.sub( sText, string.len(text) + 1 )
  224. if string.len(text) > w then
  225. -- Print a multiline word
  226. while string.len( text ) > 0 do
  227. if x > w then
  228. newLine()
  229. end
  230. term.write( text )
  231. text = string.sub( text, (w-x) + 2 )
  232. x,y = term.getCursorPos()
  233. end
  234. else
  235. -- Print a word normally
  236. if x + string.len(text) - 1 > w then
  237. newLine()
  238. end
  239. term.write( text )
  240. x,y = term.getCursorPos()
  241. end
  242. end
  243. end
  244.  
  245. return nLinesPrinted
  246. end
  247.  
  248. function print( ... )
  249. local nLinesPrinted = 0
  250. local nLimit = select("#", ... )
  251. for n = 1, nLimit do
  252. local s = tostring( select( n, ... ) )
  253. if n < nLimit then
  254. s = s .. "\t"
  255. end
  256. nLinesPrinted = nLinesPrinted + write( s )
  257. end
  258. nLinesPrinted = nLinesPrinted + write( "\n" )
  259. return nLinesPrinted
  260. end
  261.  
  262. function printError( ... )
  263. local oldColour
  264. if term.isColour() then
  265. oldColour = term.getTextColour()
  266. term.setTextColour( colors.red )
  267. end
  268. print( ... )
  269. if term.isColour() then
  270. term.setTextColour( oldColour )
  271. end
  272. end
  273.  
  274. function read( _sReplaceChar, _tHistory, _fnComplete )
  275. term.setCursorBlink( true )
  276.  
  277. local sLine = ""
  278. local nHistoryPos
  279. local nPos = 0
  280. if _sReplaceChar then
  281. _sReplaceChar = string.sub( _sReplaceChar, 1, 1 )
  282. end
  283.  
  284. local tCompletions
  285. local nCompletion
  286. local function recomplete()
  287. if _fnComplete and nPos == string.len(sLine) then
  288. tCompletions = _fnComplete( sLine )
  289. if tCompletions and #tCompletions > 0 then
  290. nCompletion = 1
  291. else
  292. nCompletion = nil
  293. end
  294. else
  295. tCompletions = nil
  296. nCompletion = nil
  297. end
  298. end
  299.  
  300. local function uncomplete()
  301. tCompletions = nil
  302. nCompletion = nil
  303. end
  304.  
  305. local w = term.getSize()
  306. local sx = term.getCursorPos()
  307.  
  308. local function redraw( _bClear )
  309. local nScroll = 0
  310. if sx + nPos >= w then
  311. nScroll = (sx + nPos) - w
  312. end
  313.  
  314. local cx,cy = term.getCursorPos()
  315. term.setCursorPos( sx, cy )
  316. local sReplace = (_bClear and " ") or _sReplaceChar
  317. if sReplace then
  318. term.write( string.rep( sReplace, math.max( string.len(sLine) - nScroll, 0 ) ) )
  319. else
  320. term.write( string.sub( sLine, nScroll + 1 ) )
  321. end
  322.  
  323. if nCompletion then
  324. local sCompletion = tCompletions[ nCompletion ]
  325. local oldText, oldBg
  326. if not _bClear then
  327. oldText = term.getTextColor()
  328. oldBg = term.getBackgroundColor()
  329. term.setTextColor( colors.white )
  330. term.setBackgroundColor( colors.gray )
  331. end
  332. if sReplace then
  333. term.write( string.rep( sReplace, string.len( sCompletion ) ) )
  334. else
  335. term.write( sCompletion )
  336. end
  337. if not _bClear then
  338. term.setTextColor( oldText )
  339. term.setBackgroundColor( oldBg )
  340. end
  341. end
  342.  
  343. term.setCursorPos( sx + nPos - nScroll, cy )
  344. end
  345.  
  346. local function clear()
  347. redraw( true )
  348. end
  349.  
  350. recomplete()
  351. redraw()
  352.  
  353. local function acceptCompletion()
  354. if nCompletion then
  355. -- Clear
  356. clear()
  357.  
  358. -- Find the common prefix of all the other suggestions which start with the same letter as the current one
  359. local sCompletion = tCompletions[ nCompletion ]
  360. sLine = sLine .. sCompletion
  361. nPos = string.len( sLine )
  362.  
  363. -- Redraw
  364. recomplete()
  365. redraw()
  366. end
  367. end
  368. while true do
  369. local sEvent, param = os.pullEvent()
  370. if sEvent == "char" then
  371. -- Typed key
  372. clear()
  373. sLine = string.sub( sLine, 1, nPos ) .. param .. string.sub( sLine, nPos + 1 )
  374. nPos = nPos + 1
  375. recomplete()
  376. redraw()
  377.  
  378. elseif sEvent == "paste" then
  379. -- Pasted text
  380. clear()
  381. sLine = string.sub( sLine, 1, nPos ) .. param .. string.sub( sLine, nPos + 1 )
  382. nPos = nPos + string.len( param )
  383. recomplete()
  384. redraw()
  385.  
  386. elseif sEvent == "key" then
  387. if param == keys.enter then
  388. -- Enter
  389. if nCompletion then
  390. clear()
  391. uncomplete()
  392. redraw()
  393. end
  394. break
  395.  
  396. elseif param == keys.left then
  397. -- Left
  398. if nPos > 0 then
  399. clear()
  400. nPos = nPos - 1
  401. recomplete()
  402. redraw()
  403. end
  404.  
  405. elseif param == keys.right then
  406. -- Right
  407. if nPos < string.len(sLine) then
  408. -- Move right
  409. clear()
  410. nPos = nPos + 1
  411. recomplete()
  412. redraw()
  413. else
  414. -- Accept autocomplete
  415. acceptCompletion()
  416. end
  417.  
  418. elseif param == keys.up or param == keys.down then
  419. -- Up or down
  420. if nCompletion then
  421. -- Cycle completions
  422. clear()
  423. if param == keys.up then
  424. nCompletion = nCompletion - 1
  425. if nCompletion < 1 then
  426. nCompletion = #tCompletions
  427. end
  428. elseif param == keys.down then
  429. nCompletion = nCompletion + 1
  430. if nCompletion > #tCompletions then
  431. nCompletion = 1
  432. end
  433. end
  434. redraw()
  435.  
  436. elseif _tHistory then
  437. -- Cycle history
  438. clear()
  439. if param == keys.up then
  440. -- Up
  441. if nHistoryPos == nil then
  442. if #_tHistory > 0 then
  443. nHistoryPos = #_tHistory
  444. end
  445. elseif nHistoryPos > 1 then
  446. nHistoryPos = nHistoryPos - 1
  447. end
  448. else
  449. -- Down
  450. if nHistoryPos == #_tHistory then
  451. nHistoryPos = nil
  452. elseif nHistoryPos ~= nil then
  453. nHistoryPos = nHistoryPos + 1
  454. end
  455. end
  456. if nHistoryPos then
  457. sLine = _tHistory[nHistoryPos]
  458. nPos = string.len( sLine )
  459. else
  460. sLine = ""
  461. nPos = 0
  462. end
  463. uncomplete()
  464. redraw()
  465.  
  466. end
  467.  
  468. elseif param == keys.backspace then
  469. -- Backspace
  470. if nPos > 0 then
  471. clear()
  472. sLine = string.sub( sLine, 1, nPos - 1 ) .. string.sub( sLine, nPos + 1 )
  473. nPos = nPos - 1
  474. recomplete()
  475. redraw()
  476. end
  477.  
  478. elseif param == keys.home then
  479. -- Home
  480. if nPos > 0 then
  481. clear()
  482. nPos = 0
  483. recomplete()
  484. redraw()
  485. end
  486.  
  487. elseif param == keys.delete then
  488. -- Delete
  489. if nPos < string.len(sLine) then
  490. clear()
  491. sLine = string.sub( sLine, 1, nPos ) .. string.sub( sLine, nPos + 2 )
  492. recomplete()
  493. redraw()
  494. end
  495.  
  496. elseif param == keys["end"] then
  497. -- End
  498. if nPos < string.len(sLine ) then
  499. clear()
  500. nPos = string.len(sLine)
  501. recomplete()
  502. redraw()
  503. end
  504.  
  505. elseif param == keys.tab then
  506. -- Tab (accept autocomplete)
  507. acceptCompletion()
  508.  
  509. end
  510.  
  511. elseif sEvent == "term_resize" then
  512. -- Terminal resized
  513. w = term.getSize()
  514. redraw()
  515.  
  516. end
  517. end
  518.  
  519. local cx, cy = term.getCursorPos()
  520. term.setCursorBlink( false )
  521. term.setCursorPos( w + 1, cy )
  522. print()
  523.  
  524. return sLine
  525. end
  526.  
  527. loadfile = function( _sFile, _tEnv )
  528. local file = fs.open( _sFile, "r" )
  529. if file then
  530. local func, err = load( file.readAll(), fs.getName( _sFile ), "t", _tEnv )
  531. file.close()
  532. return func, err
  533. end
  534. return nil, "File not found"
  535. end
  536.  
  537. dofile = function( _sFile )
  538. local fnFile, e = loadfile( _sFile, _G )
  539. if fnFile then
  540. return fnFile()
  541. else
  542. error( e, 2 )
  543. end
  544. end
  545.  
  546. -- Install the rest of the OS api
  547. function os.run( _tEnv, _sPath, ... )
  548. local tArgs = { ... }
  549. local tEnv = _tEnv
  550. setmetatable( tEnv, { __index = _G } )
  551. local fnFile, err = loadfile( _sPath, tEnv )
  552. if fnFile then
  553. local ok, err = pcall( function()
  554. fnFile( table.unpack( tArgs ) )
  555. end )
  556. if not ok then
  557. if err and err ~= "" then
  558. printError( err )
  559. end
  560. return false
  561. end
  562. return true
  563. end
  564. if err and err ~= "" then
  565. printError( err )
  566. end
  567. return false
  568. end
  569.  
  570. local tAPIsLoading = {}
  571. function os.loadAPI( _sPath )
  572. local sName = fs.getName( _sPath )
  573. if tAPIsLoading[sName] == true then
  574. printError( "API "..sName.." is already being loaded" )
  575. return false
  576. end
  577. tAPIsLoading[sName] = true
  578.  
  579. local tEnv = {}
  580. setmetatable( tEnv, { __index = _G } )
  581. local fnAPI, err = loadfile( _sPath, tEnv )
  582. if fnAPI then
  583. local ok, err = pcall( fnAPI )
  584. if not ok then
  585. printError( err )
  586. tAPIsLoading[sName] = nil
  587. return false
  588. end
  589. else
  590. printError( err )
  591. tAPIsLoading[sName] = nil
  592. return false
  593. end
  594.  
  595. local tAPI = {}
  596. for k,v in pairs( tEnv ) do
  597. if k ~= "_ENV" then
  598. tAPI[k] = v
  599. end
  600. end
  601.  
  602. _G[sName] = tAPI
  603. tAPIsLoading[sName] = nil
  604. return true
  605. end
  606.  
  607. function os.unloadAPI( _sName )
  608. if _sName ~= "_G" and type(_G[_sName]) == "table" then
  609. _G[_sName] = nil
  610. end
  611. end
  612.  
  613. function os.sleep( nTime )
  614. sleep( nTime )
  615. end
  616.  
  617. local nativeShutdown = os.shutdown
  618. function os.shutdown()
  619. nativeShutdown()
  620. while true do
  621. coroutine.yield()
  622. end
  623. end
  624.  
  625. local nativeReboot = os.reboot
  626. function os.reboot()
  627. nativeReboot()
  628. while true do
  629. coroutine.yield()
  630. end
  631. end
  632.  
  633. -- Install the lua part of the HTTP api (if enabled)
  634. if http then
  635. local nativeHTTPRequest = http.request
  636.  
  637. local function wrapRequest( _url, _post, _headers )
  638. local ok, err = nativeHTTPRequest( _url, _post, _headers )
  639. if ok then
  640. while true do
  641. local event, param1, param2 = os.pullEvent()
  642. if event == "http_success" and param1 == _url then
  643. return param2
  644. elseif event == "http_failure" and param1 == _url then
  645. return nil, param2
  646. end
  647. end
  648. end
  649. return nil, err
  650. end
  651.  
  652. http.get = function( _url, _headers )
  653. return wrapRequest( _url, nil, _headers )
  654. end
  655.  
  656. http.post = function( _url, _post, _headers )
  657. return wrapRequest( _url, _post or "", _headers )
  658. end
  659.  
  660. http.request = function( _url, _post, _headers )
  661. local ok, err = nativeHTTPRequest( _url, _post, _headers )
  662. if not ok then
  663. os.queueEvent( "http_failure", _url, err )
  664. end
  665. return ok, err
  666. end
  667. end
  668.  
  669. -- Install the lua part of the FS api
  670. local tEmpty = {}
  671. function fs.complete( sPath, sLocation, bIncludeFiles, bIncludeDirs )
  672. bIncludeFiles = (bIncludeFiles ~= false)
  673. bIncludeDirs = (bIncludeDirs ~= false)
  674. local sDir = sLocation
  675. local nStart = 1
  676. local nSlash = string.find( sPath, "[/\\]", nStart )
  677. if nSlash == 1 then
  678. sDir = ""
  679. nStart = 2
  680. end
  681. local sName
  682. while not sName do
  683. local nSlash = string.find( sPath, "[/\\]", nStart )
  684. if nSlash then
  685. local sPart = string.sub( sPath, nStart, nSlash - 1 )
  686. sDir = fs.combine( sDir, sPart )
  687. nStart = nSlash + 1
  688. else
  689. sName = string.sub( sPath, nStart )
  690. end
  691. end
  692.  
  693. if fs.isDir( sDir ) then
  694. local tResults = {}
  695. if bIncludeDirs and sPath == "" then
  696. table.insert( tResults, "." )
  697. end
  698. if sDir ~= "" then
  699. if sPath == "" then
  700. table.insert( tResults, (bIncludeDirs and "..") or "../" )
  701. elseif sPath == "." then
  702. table.insert( tResults, (bIncludeDirs and ".") or "./" )
  703. end
  704. end
  705. local tFiles = fs.list( sDir )
  706. for n=1,#tFiles do
  707. local sFile = tFiles[n]
  708. if #sFile >= #sName and string.sub( sFile, 1, #sName ) == sName then
  709. local bIsDir = fs.isDir( fs.combine( sDir, sFile ) )
  710. local sResult = string.sub( sFile, #sName + 1 )
  711. if bIsDir then
  712. table.insert( tResults, sResult .. "/" )
  713. if bIncludeDirs and #sResult > 0 then
  714. table.insert( tResults, sResult )
  715. end
  716. else
  717. if bIncludeFiles and #sResult > 0 then
  718. table.insert( tResults, sResult )
  719. end
  720. end
  721. end
  722. end
  723. return tResults
  724. end
  725. return tEmpty
  726. end
  727.  
  728. -- Load APIs
  729. local bAPIError = false
  730. local tApis = fs.list( "rom/apis" )
  731. for n,sFile in ipairs( tApis ) do
  732. if string.sub( sFile, 1, 1 ) ~= "." then
  733. local sPath = fs.combine( "rom/apis", sFile )
  734. if not fs.isDir( sPath ) then
  735. if not os.loadAPI( sPath ) then
  736. bAPIError = true
  737. end
  738. end
  739. end
  740. end
  741.  
  742. if turtle then
  743. -- Load turtle APIs
  744. local tApis = fs.list( "rom/apis/turtle" )
  745. for n,sFile in ipairs( tApis ) do
  746. if string.sub( sFile, 1, 1 ) ~= "." then
  747. local sPath = fs.combine( "rom/apis/turtle", sFile )
  748. if not fs.isDir( sPath ) then
  749. if not os.loadAPI( sPath ) then
  750. bAPIError = true
  751. end
  752. end
  753. end
  754. end
  755. end
  756.  
  757. if pocket and fs.isDir( "rom/apis/pocket" ) then
  758. -- Load pocket APIs
  759. local tApis = fs.list( "rom/apis/pocket" )
  760. for n,sFile in ipairs( tApis ) do
  761. if string.sub( sFile, 1, 1 ) ~= "." then
  762. local sPath = fs.combine( "rom/apis/pocket", sFile )
  763. if not fs.isDir( sPath ) then
  764. if not os.loadAPI( sPath ) then
  765. bAPIError = true
  766. end
  767. end
  768. end
  769. end
  770. end
  771.  
  772. if commands and fs.isDir( "rom/apis/command" ) then
  773. -- Load command APIs
  774. if os.loadAPI( "rom/apis/command/commands" ) then
  775. -- Add a special case-insensitive metatable to the commands api
  776. local tCaseInsensitiveMetatable = {
  777. __index = function( table, key )
  778. local value = rawget( table, key )
  779. if value ~= nil then
  780. return value
  781. end
  782. if type(key) == "string" then
  783. local value = rawget( table, string.lower(key) )
  784. if value ~= nil then
  785. return value
  786. end
  787. end
  788. return nil
  789. end
  790. }
  791. setmetatable( commands, tCaseInsensitiveMetatable )
  792. setmetatable( commands.async, tCaseInsensitiveMetatable )
  793.  
  794. -- Add global "exec" function
  795. exec = commands.exec
  796. else
  797. bAPIError = true
  798. end
  799. end
  800.  
  801. if bAPIError then
  802. print( "Press any key to continue" )
  803. os.pullEvent( "key" )
  804. term.clear()
  805. term.setCursorPos( 1,1 )
  806. end
  807.  
  808. -- Set default settings
  809. settings.set( "shell.allow_startup", true )
  810. settings.set( "shell.allow_disk_startup", (commands == nil) )
  811. settings.set( "shell.autocomplete", true )
  812. settings.set( "edit.autocomplete", true )
  813. settings.set( "lua.autocomplete", true )
  814. settings.set( "list.show_hidden", false )
  815. if term.isColour() then
  816. settings.set( "bios.use_multishell", true )
  817. end
  818. if _CC_DEFAULT_SETTINGS then
  819. for sPair in string.gmatch( _CC_DEFAULT_SETTINGS, "[^,]+" ) do
  820. local sName, sValue = string.match( sPair, "([^=]*)=(.*)" )
  821. if sName and sValue then
  822. local value
  823. if sValue == "true" then
  824. value = true
  825. elseif sValue == "false" then
  826. value = false
  827. elseif sValue == "nil" then
  828. value = nil
  829. elseif tonumber(sValue) then
  830. value = tonumber(sValue)
  831. else
  832. value = sValue
  833. end
  834. if value ~= nil then
  835. settings.set( sName, value )
  836. else
  837. settings.unset( sName )
  838. end
  839. end
  840. end
  841. end
  842.  
  843. -- Load user settings
  844. if fs.exists( ".settings" ) then
  845. settings.load( ".settings" )
  846. end
  847.  
  848. -- Run the shell
  849. getfenv = nativegetfenv
  850. setfenv = nativesetfenv
  851. local ok, err = pcall( function()
  852. parallel.waitForAny(
  853. function()
  854. local sShell
  855. if term.isColour() and settings.get( "bios.use_multishell" ) then
  856. sShell = "rom/programs/advanced/multishell"
  857. else
  858. sShell = "rom/programs/shell"
  859. end
  860. os.run( {}, sShell )
  861. os.run( {}, "rom/programs/shutdown" )
  862. end,
  863. function()
  864. rednet.run()
  865. end )
  866. end )
  867.  
  868. -- If the shell errored, let the user read it.
  869. term.redirect( term.native() )
  870. if not ok then
  871. printError( err )
  872. pcall( function()
  873. term.setCursorBlink( false )
  874. print( "Press any key to continue" )
  875. os.pullEvent( "key" )
  876. end )
  877. end
  878.  
  879. -- End
  880. os.shutdown()
Advertisement
Add Comment
Please, Sign In to add comment